DataGridView 已过滤

问题描述 投票:0回答:1

如果第一列的复选框被标记,我必须在运行时突出显示 datagridview 行。我无法使用正常的

for each
循环对行进行着色,因为大约有 3000 行,而且需要很长时间。

我应该直接从

for each
循环中过滤行,条件是 Column1 = True ... ...你能帮我找到正确的概要吗:我尝试过:

For Each selRows As DataGridViewRow In myDataGrid.SelectedColumns(0).Equals("Column1 = true")
  myDataGrid.Rows(selRows.index).DefaultCellStyle.BackColor = Color.LightGreen
Next

但是不起作用

谢谢你

vb.net foreach datagridview
1个回答
0
投票

您可以使用 CellPainting 事件

Private Sub dgv_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles dgv.CellPainting
   '   check if the row is the header row
   If e.RowIndex = -1 Then
       Exit Sub
   End If
   '   cast the row to the correct data type, here I'll assume this is a datarow
   Dim row As DataRow = CType(dgv.Rows(e.RowIndex).DataBoundItem, DataRowView).Row
   '   perform your check 
   If CType(row("Column1"), Boolean) Then
       dgv.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.LightGreen
   End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.