1

每当用户至少选择一个时,我需要将在 DataGridView 中选择的行数显示到标签中。但我不知道该怎么做。我也想知道我应该使用什么事件。

4

4 回答 4

2

要获取所选行数,您可以使用

Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)

然后在标签中显示;

lblLabel = selectedRowCount.ToString()
于 2013-09-16T05:26:20.753 回答
0

需要设置YourGridView.MultiSelect=true;MultiSelect 当 MultiSelect 属性设置为 true 时,可以在 DataGridView 控件中选择多个元素(单元格、行或列)。要选择多个元素,用户可以在单击要选择的元素时按住 CTRL 键。可以通过单击要选择的第一个元素来选择连续的元素,然后在按住 SHIFT 键的同时单击要选择的最后一个元素。那么您可以使用 SelectRows。

MessageBox.Show(yourDataGridView.SelectedRows.Count.ToString());
于 2013-09-16T05:25:51.453 回答
-1

您要查找的事件是网格的SelectionChanged事件。

您应该将网格的MultiSelecttrue属性设置为允许多选。要获取所选行数,您可以使用SelectedRows属性:

MyLabel.Text = MyGrid.SelectedRows.Count().ToString()
于 2013-09-16T05:42:53.033 回答
-1
Data Grid Mouse Down Event

Dim CRow As Int32 = DataGridView.HitTest(e.X, e.Y).RowIndex
DataGridView.Rows(CRow).Cells(ColumnName).Value()
于 2016-06-22T12:59:42.513 回答