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

Highlighting Column/Row Headers

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?

3 Replies

AD Administrator Syncfusion Team 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;
	}
}


AA Akshay Arora 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).


AA Akshay Arora 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;
					break;
				}
			}
		}

Loader.
Live Chat Icon For mobile
Up arrow icon