User (Old forums)MemberApril 2, 2009 at 4:32 amPost count: 23064
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)User (Old forums)MemberApril 2, 2009 at 3:35 pmPost count: 23064
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.
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)User (Old forums)MemberApril 6, 2009 at 5:42 amPost count: 23064
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,
Imported from legacy forums. Posted by Ogren (had 1574 views)User (Old forums)MemberApril 6, 2009 at 10:56 amPost count: 23064
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.
Imported from legacy forums. Posted by Ogren (had 4008 views)User (Old forums)MemberApril 25, 2009 at 7:21 pmPost count: 23064
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
Imported from legacy forums. Posted by Stephen (had 2310 views)User (Old forums)MemberApril 27, 2009 at 3:08 pmPost count: 23064
- You must be logged in to reply to this topic.