Background colour of DataGrid

Hi,

I have some problem on changing the background colour of datagrid

I have a datatable to link to the datagrid

I want to use the each row's background colour to indicate the status of the record

but I hard to find a method to chnage the background colour individually but can find a method to change the whole datagrid background colour

How can I chnage the background colour of each row individually

Thank you



Answer this question

Background colour of DataGrid

  • Val Savvateev


    class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" align=left>private void myDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
      {
       int colIndex = e.ColumnIndex;
       int rowIndex = e.RowIndex;

       if (rowIndex >= 0 && colIndex >= 0)
       {
        DataGridViewRow theRow = dataGridView1.Rows[rowIndex];
        if (theRow.Cells[colIndex].Value)//your condition here
    < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

            theRow.DefaultCellStyle.BackColor = Color.Red;
       }
      }

     


     



  • scienceboy

    I am usinf VS2002........

    this method seems work only under VS2005........

    anyway, thank you for your help


  • tfr294036

    Moved to Windows Forms General forum.


  • Background colour of DataGrid