【问题标题】:Listview check/uncheck checkbox on row click [closed]Listview选中/取消选中行单击复选框[关闭]
【发布时间】:2018-09-01 00:49:32
【问题描述】:

当我单击行时,我想在列表视图中选中或取消选中我的复选框。

【问题讨论】:

标签: vb.net listview checkbox


【解决方案1】:

假设这是 WinForms 并且你有 ListView 控件的FullRowSelect = true,你可以使用控件的 MouseDown 事件来找到被点击的行:

void listView1_MouseDown(object sender, MouseEventArgs e) {
  var lvi = listView1.GetItemAt(e.X, e.Y);
  if (lvi != null) {
    lvi.Checked = !lvi.Checked;
  }
}

VB.Net:

Private Sub ListView1_MouseDown(sender As Object, e As MouseEventArgs) Handles ListView1.MouseDown
  Dim lvi = ListView1.GetItemAt(e.X, e.Y)
  If lvi IsNot Nothing Then
    lvi.Checked = Not lvi.Checked
  End If
End Sub 

【讨论】:

  • 非常感谢,完美运行。
  • @KoenAmant 抱歉,我没注意标签。用您的 vb.net 版本更新了帖子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多