我是个菜鸟。我从这里学到了很多东西,但是这个我找不到答案。我正在使用 Visual Studio Pro 2015。
我发现了这个问题,但答案不适用于我的应用程序:
VB.Net - Is there any way to count the number of selected rows in a datagridview?
我有一个 Windows 窗体应用程序,它有一个单列数据 GridView ,它是通过在运行时逐行读取文本文件来填充的。
我需要显示(在标签中)用户在 datagridview 控件中选择的行数。
我有这个:
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
Dim selectedRowCount As Integer
selectedRowCount = DataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)
lblNumSelected.Text = selectedRowCount.ToString()
End Sub
或者这个:
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
lblNumSelected.Text = DataGridView1.SelectedRows.Count().ToString()
End Sub
无论选择了多少行,这两种方法都返回 0(零)。 谢谢你帮助我。
最佳答案
在您的 DataGridView
上,将 .SelectionMode
属性设置为 FullRowSelect
,然后使用 .SelectedRows.Count
属性(property)。
关于.net - 如何计算datagridview vb.net中选中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34326155/