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.

Highlight a row based on record value from hidden column

Thread ID:

Created:

Updated:

Platform:

Replies:

127273 Nov 7,2016 05:31 PM Nov 8,2016 08:48 AM Windows Forms 1
loading
Tags: GridGroupingControl
Devi
Asked On November 7, 2016 05:31 PM

Hi,

I have a gridgrouping control databound to a datatable in dataset. I have a hidden column (removed it from visible columns). I would like to highlight the row in the grid based on value in the hidden column. Please let me know which event to handle for this. The row should be highlighted using backcolor irrespective of whether user clicked on it or not. Please clarify this.

Thanks,
Devi.

Amal Raj Umapathy Selvam [Syncfusion]
Replied On November 8, 2016 08:48 AM

Hi Devi, 

Thanks for using Syncfusion products. 

The reported scenario of highlighting the row based on hidden columns cell value can be done using Conditional Formatting. By default when condition formatting are enabled,  the SelectionBackColor  will override the highlighted record’s BackColor, this can be resolved by using TableControlDrawCellDisplayText event. Please make use of the below code, 
 
Code Snippet 
//Conditional Formatting. 
GridConditionalFormatDescriptor descriptor1 = new GridConditionalFormatDescriptor(); 
descriptor1.Appearance.AnyRecordFieldCell.BackColor = Color.Green; 
descriptor1.Expression = "[ContactTitle] = \'Sales Manager\'"
this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(descriptor1); 
 
//Event Subscription. 
this.gridGroupingControl1.TableControlDrawCellDisplayText += new GridTableControlDrawCellDisplayTextEventHandler(gridGroupingControl1_TableControlDrawCellDisplayText); 
 
void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e) 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    if (style == null || style.TableCellIdentity == null || style.TableCellIdentity.Column == null  
        || style.TableCellIdentity.DisplayElement.GetRecord() == null
        return
    if (style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell  
        || style.TableCellIdentity.TableCellType == GridTableCellType.AnyRecordFieldCell  
        || style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell) 
    { 
        Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
        if (descriptor1.CompareRecord(record) && record.IsCurrent) 
        { 
            Rectangle rectangle = e.Inner.ClipBounds; 
            rectangle.Height += 4; 
            rectangle.Width += 4; 
            e.Inner.Graphics.FillRectangle(new SolidBrush(Color.Green), rectangle); 
        } 
    } 
 
Sample Link 
 
Regards, 
Amal Raj U. 


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.

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.

;