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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Overriding Paint method for DataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

179 Apr 16,2002 10:54 AM UTC Apr 21,2002 11:45 AM UTC Windows Forms 3
loading
Tags: FAQ
KDA
Asked On April 16, 2002 10:54 AM UTC

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

Dennis
Replied On April 18, 2002 01:23 PM UTC

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

Clay Burch [Syncfusion]
Replied On April 21, 2002 11:29 AM UTC

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); }

Clay Burch [Syncfusion]
Replied On April 21, 2002 11:45 AM UTC

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"];

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;