Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Datagridview着色行_Vb.net_Datagridview_Colors - Fatal编程技术网

Vb.net Datagridview着色行

Vb.net Datagridview着色行,vb.net,datagridview,colors,Vb.net,Datagridview,Colors,我目前面临一个问题,我正在尝试使用条件IF为行着色,但我不知道为什么程序会出现错误,无法找到名为“Cor”的列。 这是我的密码: Private Sub datagridListagem_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles datagridListagem.CellFormatting If datagridListagem.Rows(e.RowIndex)

我目前面临一个问题,我正在尝试使用条件IF为行着色,但我不知道为什么程序会出现错误,无法找到名为“Cor”的列。 这是我的密码:

Private Sub datagridListagem_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles datagridListagem.CellFormatting

    If datagridListagem.Rows(e.RowIndex).Cells("Cor").Value.ToString() = "3" Then

            e.CellStyle.BackColor = Color.Green

        ElseIf datagridListagem.Rows(e.RowIndex).Cells("Cor").Value.ToString() = "2" Then
            e.CellStyle.BackColor = Color.Orange
        ElseIf datagridListagem.Rows(e.RowIndex).Cells("Cor").Value.ToString() = "1" Then
            e.CellStyle.BackColor = Color.Gray

        End If

End Sub
你能帮我吗

多谢各位

Private Sub datagridListagem_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles datagridListagem.CellFormatting
    If datagridListagem("Cor", e.RowIndex).Value = "3" Then
        e.CellStyle.BackColor = Color.Green
    ElseIf datagridListagem("Cor", e.RowIndex).Value = "2" Then
        e.CellStyle.BackColor = Color.Orange
    ElseIf datagridListagem("Cor", e.RowIndex).Value = "1" Then
        e.CellStyle.BackColor = Color.Gray
    End If
End Sub
Cor
是否存在于您的
DatagridView
中?检查您的
DatagridView
并检查
Cor
是否存在于
列中


如何将gridview与数据源绑定。。请检查数据源是否有datatable列或对象数据源的属性。。如果列名不同,请使用正确的列名。请使用索引而不是列名,可能是列名写错了或不存在。我使用的是正确的列。我通过Access数据库中的数据源绑定数据。当我打开程序时,数据出现,列100%命名为“Cor”。它存在于我的datagridview中检查打印屏幕是否存在。我看到您的代码错误,您使用的是
DataPropertyName
,但必须使用is
Name
字段。请使用
Name
而不是
DataPropertyName
DataPropertyName
只需将其保留为空或无,并将您的
名称设置为
Cor
。希望能解决您的问题。我认为上面的代码是有效的,但是你的
datagridView
似乎是错误的。它有效了,我很抱歉这是一个愚蠢的新手错误,我没有注意到我没有更改它。非常感谢。