Coloring Datagrid rows based on value inside of dataset

Hi

I am developing a windows application that connects to a sql database.  I have a datagrid that has a datasource of a dataset.  I am trying to color the rows of the datagrid based on a value inside of the dataset.  I have read the article "Customizing the Windows Forms Datagrid" and I am having trouble figuring out where some of the code that has been provided needs to go.  Any assistance would be greatly appreciated.

Thanks


Answer this question

Coloring Datagrid rows based on value inside of dataset

  • gidon

    Thank You for your response.  

    I have successfully colored an Individual Cell based on a value.  Now if I could just color that entire row that would be fantastic.

  • mizd

    hi, where do i put this code from. Any particular datagrid event. 

    I tried to put it in a private methods is says _myGrid (mygrid IN MYEXAMPLE) is DOES NOT CONTAIN DEFINITION FOR ROWS

  • Craig Spargo

    Take a look here

    http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx#44

  • Brian Knox

    Thank you for your response.

    Is this an example in C++   I am trying to use logic in vb and I am finding it difficult to translate the following code to vb syntax

    <Code>
    foreach(DataGridRow row in _myGrid.Rows)   

          {

                bool isBold = (bool)row["isBold"].Value;

                if (isBold)

               {

                    row.DefaultCellStyle.Font = bold_font;

               }  

           }
    </Code>

    any suggestions

  • Patrick D

    You may use the following cose:

    grid.Rows[i].DefaultCellStyle.Color = someColor;

    this will change the entire row style.

    My code is in C# but the VB version is pretty much the same.

    Hope it helps.

  • PParisot

    Example to set row to bold when cell isBold is true


           // This is the style to change to matching rows
           Font bold_font = new Font("Arial", 9F, FontStyle.Bold);

           foreach(DataGridRow row in _myGrid.Rows)   
          {
                bool isBold = (bool)row["isBold"].Value;
                if (isBold)
               {
                    row.DefaultCellStyle.Font = bold_font;
               }  
           }



    In the same manner you may cahnge Style.Color and other Style properties acording to your data.
    Note that the (bool)row["isBold"].Value command will work only if all of the items will have true or false in them (null value will give an Exception).

    Hope it helps.

  • Coloring Datagrid rows based on value inside of dataset