We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Overriding Paint method for DataGrid

I am attempting to override the Paint method for a derived class (clsMyDataGridTextBoxColumn) that inherits from DataGridTextBoxColumn. The behavior I have found is that when I override the Paint method to dynamically change a single row's backcolor (via the backBrush object of the base class' Paint call) based on the row's content, it will change the color, but it seems to disable the ability for a row to be selected (highlighted). By the way, I am also, disabling the edit cell feature, by overriding the Edit method and leaving it empty. I have commented out the override Edit method to see if that was causing the highlight not to work, but I got the same results. Also, I cannot alter the properties of the DataGrid anymore either, for instance I changed the color of the GridLines, but it had no effect. Do I have to override all of these properties and implement a select (highlight) capability in my derived class or am I missing something simple here? Thanks for your help in advance. Karl

3 Replies

DE Dennis April 18, 2002 08:23 AM

Well if you succeed please post it here, I am very curious how it is done.


CB Clay Burch Syncfusion Team April 21, 2002 06:29 AM

You might try not changing the background color in your Paint override if the rowNum passed in is selected. I added this code to the sample in our Windows Forms FAQ about coloring individual cells and it allowed the highlighting of selected cells to go through OK. try { if(!this.DataGridTableStyle.DataGrid.IsSelected(rowNum)) { object o = this.GetColumnValueAtRow(source, rowNum); if( o!= null) { char c = ((string)o)[0]; if( c > 'F') { // could be as simple as // backBrush = new SolidBrush(Color.Pink); // or something fnacier... backBrush = new LinearGradientBrush(bounds, Color.FromArgb(255, 200, 200), Color.FromArgb(128, 20, 20), LinearGradientMode.BackwardDiagonal); foreBrush = new SolidBrush(Color.White); } } } } catch(Exception ex){ /* empty catch */ } finally{ // make sure the base class gets called to do the drawing with // the possibly changed brushes base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); }


CB Clay Burch Syncfusion Team April 21, 2002 06:45 AM

Also in the sample in our Windows Forms FAQ, setting the GridLineColor property on the tablestyle seems to work as well. // make the dataGrid use our new tablestyle and bind it to our table dataGrid1.TableStyles.Clear(); tableStyle.GridLineColor = Color.Red; //change gridline color added***** dataGrid1.TableStyles.Add(tableStyle); dataGrid1.DataSource = _dataSet.Tables["customers"];

Loader.
Live Chat Icon For mobile
Up arrow icon