开发者

How do I set background color for a datagrid row programmatically

开发者 https://www.devze.com 2023-01-29 12:55 出处:网络
I have a datagrid (not gridview or datagridview) in windows forms. It was created in Microsoft Visual Studio 2003. I have converted to 2008. I am supposed to change the datarow of the datagrid based o

I have a datagrid (not gridview or datagridview) in windows forms. It was created in Microsoft Visual Studio 2003. I have converted to 2008. I am supposed to change the datarow of the datagrid based on a condition.

I have googled and found some examples such as

void myDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)

But I do not have any " DataGridRowEventArgs "arguments.

also I found one in

http://www.syncfusion.com/faq/windowsforms/faq_c44c.aspx, where they change color of one particular cell.

But开发者_如何学Python how do I change the color of the whole row in Datagrid in Windows Form, based on some condition.

Thanks in advance.

Regards

skr


use this as hint:

    private void dataGridView1_CellFormatting(object sender,         DataGridViewCellFormattingEventArgs e)
{
    foreach (DataGridViewRow Myrow in dataGridView1.Rows) 
    {            //Here 2 cell is target value and 1 cell is Volume
        if (Convert.ToInt32(Myrow .Cells[2].Value)<Convert.ToInt32(Myrow .Cells[1].Value))// Or your condition 
        {
            Myrow .DefaultCellStyle.BackColor = Color.Red; 
        }
        else
        {
            Myrow .DefaultCellStyle.BackColor = Color.Green; 
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消