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.

Highlighting Column/Row Headers

Thread ID:





17357 Aug 6,2004 09:03 AM Aug 6,2004 11:32 AM Windows Forms 3
Tags: GridControl
Akshay Arora
Asked On August 6, 2004 09:03 AM

using GridControl I''m trying to figure out how to get the column/row headers to mark which cells are currenctly selected. I was hoping that there would be a property for this. I noticed in Designer, the Property section of the GridControl, it had a MarkRowHeader and a MarkColHeader property, but it''s set to true and it doesn''t highlight the selected row or column. I''ve come up with something, but it''s pretty slow. In the SelectionChanged event I change the background color of Row[0] and Col[0] to LightGray and then I go through the Selections property of the grid and change the appropriate column/row to a different color. This runs rather slow. I did it with BeginInit and EndInit and without to see the differences. Any suggestions?

Administrator [Syncfusion]
Replied On August 6, 2004 10:44 AM

I think you can do this using these two events.
private void grid_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
	GridCurrentCell cc = this.grid.CurrentCell;
	this.grid.RefreshRange(GridRangeInfo.Cell(0, cc.MoveFromColIndex));
	this.grid.RefreshRange(GridRangeInfo.Cell(0, cc.MoveToColIndex));
	this.grid.RefreshRange(GridRangeInfo.Cell(cc.MoveFromRowIndex, 0));
	this.grid.RefreshRange(GridRangeInfo.Cell(cc.MoveToRowIndex, 0));

private void grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
	GridCurrentCell cc = this.grid.CurrentCell;
	if((e.RowIndex == 0 && e.ColIndex == cc.ColIndex)
		|| (e.ColIndex == 0 && e.RowIndex == cc.RowIndex))
		e.Style.BackColor = mColor;

Akshay Arora
Replied On August 6, 2004 11:20 AM

Hi, This works great if only a single cell is selected. Is there a way to do it for all selected cells? I thought about perhaps using grid.RefreshRange within the SelectionChanged event, but that starts to cause Exceptions within another event (Mouse event).

Akshay Arora
Replied On August 6, 2004 11:32 AM

Hi again, I''ve actually been able to come up with a reasonable solution. For anyone else that might need this in the future:
private void HandleGridSelectionChanged( object sender, GridSelectionChangedEventArgs e ){
			if( sender is GridControl ){
				GridControl grid = (GridControl) sender;
				grid.RefreshRange( GridRangeInfo.Row( 0 ) );
				grid.RefreshRange( GridRangeInfo.Col( 0 ) );

private void HandleGridPrepareViewStyleInfo( object sender, GridPrepareViewStyleInfoEventArgs e ){
			GridControl grid = (GridControl) sender;
			for( int i = 0; i < grid.Selections.Ranges.Count; i++ ){
				GridRangeInfo gri = grid.Selections.Ranges[ i ];
				if( ( e.ColIndex >= gri.Left && e.ColIndex <= gri.Right && e.RowIndex == 0 ) ||
						( e.RowIndex >= gri.Top && e.RowIndex <= gri.Bottom && e.ColIndex == 0 ) ){
					e.Style.BackColor = Color.LightBlue;


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.