Welcome to the Xceed Community | Help
Community Search  
More Search Options

Coloring Rows based on conditions..

Sort Posts: Previous Next
  •  04-02-2009, 4:32 AM Post no. 19848

    Coloring Rows based on conditions..

    Dear All,

    Could anyone please tell me how I can get different colors for different rows based on some given conditions. 

    I'll appricite some code sample.

     

     

     


    Buddhi from Sri Lanka
  •  04-02-2009, 3:35 PM Post no. 19882 in reply to 19848

    Re: Coloring Rows based on conditions..

    You can use the AddingDataRow event, and in the event handler, get and verify the value you want, and set the BackColor (and ForeColor if applicable) to what you want.

    e.g.:

        private void Form1_Load( object sender, EventArgs e )
        {
          gridControl1.AddingDataRow += new AddingDataRowEventHandler( gridControl1_AddingDataRow );
        }


        void gridControl1_AddingDataRow( object sender, AddingDataRowEventArgs e )
        {
          string country = e.DataRow.Cells[ "Country" ].Value.ToString();
          if( country == "USA" )
          {
            e.DataRow.BackColor = Color.DeepPink;
          }
        }


    André
    Software Developer
    Xceed Software Inc.
  •  04-06-2009, 5:42 AM Post no. 19947 in reply to 19882

    Re: Coloring Rows based on conditions..

    Hi,

    I'm dealing with the same topic these days and I was wondering if you could help me with the following:

    Beside custom coloring of non selected row in the grid, I have to have custom coloring of selected row in the grid as well. I have resolved this request by  changing SelectionBackColor and SelectionForeColor on grid on SelectedRowsChanged. But another problem appears if user selects more than one row, where all selected rows are the colored according to the last row in selection as this event fires on row group selection, not for each row in the selected group.

    To further resolve this problem, I have tried to extend DataRow, but at the moment I'm having difficulties with making gridcontrol to accept this using only DataRowTemplate property.

     Thnx in advance,

    Ogren
     

    Filed under: , , ,
  •  04-06-2009, 10:56 AM Post no. 19959 in reply to 19947

    Re: Coloring Rows based on conditions..

    Hey,

    Just to report that I've resolved the problem:

    1. The problem with extending the DataRow was that I've missed to override CreateInstance method and return an instace of the extended data row class.

    2. Method PaintBackground should be extended and custom selection coloring can be done there (this.GridControl.SelectionBackColor and this.GridControl.SelectionForeColor). By doing this, each selected row can have its specific color. Good thing about this is that you'll have the SourceObject property (object on which the row is bound to) and cell content available.

     

    Cheers... 

  •  04-25-2009, 7:21 PM Post no. 20553 in reply to 19882

    Re: Coloring Rows based on conditions..

    Andre,

    I am trying to accomplish the same thing.

    from your code .. you have " gridControl1.AddingDataRow ..."

    I dont have this option on my gridControl.  The only thing similar is

    dataGridControl1.AddingNewDataItem

     any ideas?

     

    Thanks

    stephen

     

  •  04-27-2009, 3:08 PM Post no. 20574 in reply to 20553

    Re: Coloring Rows based on conditions..

    You are using the WPF DataGrid, this is a thread for the .NET Grid.

    You will need to post your question in the WPF forums http://xceed.com/CS/forums/35/ShowForum.aspx


    André
    Software Developer
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.