Dim dt As New DataTable
Dim dcColor As New DataColumn("Color", GetType(Color))
Dim dcChecked As New DataColumn("Checked", GetType(Boolean))
Dim bs As New BindingSource
dt.Columns.Add(dcColor)
dt.Columns.Add(dcChecked )
bs.DataSource = dt
DataGridView1.DataSource = bs
如果我有很多datarow(1000-100000行),我需要像这样过滤Datagridview
bs.Filter = "Checked = True"
这意味着我必须在所有datarows中迭代,以获取每个颜色值并设置回datagridviewrow。
Private Sub DataGridView1_Paint(sender As Object, e As PaintEventArgs) Handles DataGridView1.Paint
Try
For Each dr As DataRow In dt.Rows
Dim needColor As Color = dr.Item("Color")
DataGridView1.Rows(???).DefaultCellStyle.BackColor = needColor
Next
Catch ex As Exception
m_logger.AppendLog(ex)
End Try
End Sub
如何使用datarow中的值创建Datagridviewrow?