How to determine the index of selected row in gridControl

Hi, everyone

I'd like to know how can I change the background of selected row according to user selection (something else than grd_cellclick, of course) when he clicks on arrows button, for example.

Regards,
Allon

2 Replies

KM Kathiresan M Syncfusion Team August 26, 2009 09:09 AM UTC

Hi Allon,


You could make use of PrepareViewStyleInfo event for this as illustrated below.

/// Highlight the current row
private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
GridControlBase grid = gridControl1;
GridCurrentCell cc = gridControl1.CurrentCell;

// Highlight the current row with SystemColors.Highlight and bold font
if (e.RowIndex > grid.Model.Rows.HeaderCount && e.ColIndex > grid.Model.Cols.HeaderCount
&& cc.HasCurrentCellAt(e.RowIndex))
{
e.Style.Interior = new BrushInfo(SystemColors.Highlight);
e.Style.TextColor = SystemColors.HighlightText;
e.Style.Font.Bold = true;
}
}


Please look at the below sample that illustrates this better.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=Highlight-772061934.zip

Please post Grid related queries in Grid Forums instead of Tools.Windows Forums. Thanks for the co-operation.


Thanks,
Kathir


AL Allon August 26, 2009 09:38 AM UTC

Thanks, Kathir.

It works great now. From now on I'll post these posts through grid essentials.

Regards,
Allon

Loader.
Up arrow icon