2013-06-06 63 views

回答

3

试试这个..

For y As Integer = 0 To DataGridView1.Rows.Count - 1 

    For x As Integer = 0 to DataGridView1.Columns.Count - 1 

     If Datagridview.Rows(y).Cells(x).Value = "test" Then 

      DataGridView1..Rows(y).Cells(x).Style.ForeColor = Color.Red 

     End If 

    Next 

Next 
+0

是的,这是一个再次感谢你matzone! –

1

您需要遍历行并搜索文本。

在这一个你了解如何循环

Visual Basic, How do I read each row in a datagrid?

另外,如果你有多个列,并希望环通他们太多,那么你必须窝在另一个循环这个和平,像

For i As Integer = 0 To DataGridView1.ColumnCount 

     For Each row As DataGridViewRow In DataGridView1.Rows 

      If Not row.IsNewRow Then 
       If row.Cells(i).Value.ToString = "test" Then DataGridView1.Item(i, row.Index).Style.ForeColor = Color.Red 
      End If 
     Next 

    Next i 

好运

相关问题