C# 如何在c中更改RowsAdded事件的行颜色#

C# 如何在c中更改RowsAdded事件的行颜色#,c#,datagridview,colors,C#,Datagridview,Colors,我有一个dataGridview,它每1分钟刷新一次,并在其中添加新行(dataGridview)。现在,我想根据某些条件更改这些新添加行的前景色。请告诉我如何实现它 问候 Zuhaib为此,您可以从DataGridView的_RowLeave()事件中播放。。。 同样对于NewRow(),您可以检查单元格值是空还是不存在(),然后它可以应用于dataGridView单元格样式。。喜欢下面的方式 Form_Load() { DataGridViewCellStyle AStyle = n

我有一个dataGridview,它每1分钟刷新一次,并在其中添加新行(dataGridview)。现在,我想根据某些条件更改这些新添加行的前景色。请告诉我如何实现它

问候
Zuhaib

为此,您可以从DataGridView的_RowLeave()事件中播放。。。 同样对于NewRow(),您可以检查单元格值是空还是不存在(),然后它可以应用于dataGridView单元格样式。。喜欢下面的方式

Form_Load()
{
    DataGridViewCellStyle AStyle = new DataGridViewCellStyle();
    AStyle.BackColor = Color.BlueViolet;

    blah...blah...blah..
}

private void MyDataGrid1_RowLeave(Object Sender, DataGridViewCellEventArgs e)
{
    for (int I1 = 0; I1 < dataGrid1.Columns.Count - 1; I1++)
        {
            if (I1 == 3 || I1 == 5)
                {
                    dataGrid1.CurrentRow.Cells[I1].Style = AStyle;   
                }

    }

}
Form_Load()
{
DataGridViewCellStyle AStyle=新DataGridViewCellStyle();
AStyle.BackColor=Color.blueviole;
废话…废话…废话。。
}
私有void MyDataGrid1_RowLeave(对象发送方,DataGridViewCellEventArgs e)
{
for(int I1=0;I1

谢谢

您可以在RowsAdded事件中更改单元格字体。我使用Visual Basic,因此您可以将其转换为c#,代码如下:

    Private Sub DatagridView_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles DatagridView.RowsAdded
    With DirectCast(sender, DataGridView)
        If .Item(yourColumnIndex, e.RowIndex).Value Is "yourValue" Then
            .Rows.Item(e.RowIndex).DefaultCellStyle.ForeColor = Color.White
            .Rows.Item(e.RowIndex).DefaultCellStyle.BackColor = Color.DarkRed
            .Rows.Item(e.RowIndex).DefaultCellStyle.Font = New Font("Verdana", 8, FontStyle.Strikeout Or FontStyle.Bold)
        End If
    End With
End Sub

我希望这对你有用

你读过吗?另一个事件变色的例子