Home › Forums › WinForms controls › Xceed Grid for WinForms › Coloring Rows based on conditions..
-
AuthorPosts
-
#16945 |
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.
Imported from legacy forums. Posted by bdmsoft (had 2738 views)
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;
}
}Imported from legacy forums. Posted by André (had 2429 views)
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
Imported from legacy forums. Posted by Ogren (had 1574 views)
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…
Imported from legacy forums. Posted by Ogren (had 4008 views)
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
Imported from legacy forums. Posted by Stephen (had 2310 views)
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
Imported from legacy forums. Posted by André (had 2872 views)
-
AuthorPosts
- You must be logged in to reply to this topic.