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

Overriding Grid Cell Behaviour

Hi

I have a three questions regarding overriding default grid behaviour.

My grid will contain static data comprising of an image, with cells being clickable (left click action, right click as context menus) to ultimately fire events back to the main app.

Q1. How do I collect click events on header / data cells to be able to display context menus?

Q2. I am looking to override the default behaviour of the grid when either the column or row headers are clicked upon. The Default behaviour is to highlight the column or row data, respectively, who's header has been clicked on. Please see attachment. How do I 'switch off' this behaviour?

Q3. I am also looking to override the 'border' that appears around a cell that has been selected. Probably by highlighting the cell in a different background colour, for instance, or having the 'border' in red instead of black. What would be the best way of achieving this?

Best Regards,

David

Behaviour.zip

2 Replies

AD Administrator Syncfusion Team October 27, 2006 06:47 AM UTC

Hi David,

Regarding the Q1: collect the cell click

To collect the mouse click for the header cell, you need to handle the MouseDown event of the grid. Below is a code snippet.

private void grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point pt = new Point(e.X,e.Y);
int row,col;
this.grid.PointToRowCol(pt,out row, out col);
Console.WriteLine(row +":::"+ col);
}

Regarding the Q2:

There is a property that controls this behavior of selecting the cells in a grid. Try the below code

this.grid.Model.Options.AllowSelection = GridSelectionFlags.Any ^ GridSelectionFlags.Column ^ GridSelectionFlags.Row;

This should prevent the column and row selection when clicked on the column header/row header.

Regarding the Q3: change the CurrentCellBorder behavior

You can use the ShowCurrentCellBorderBehavior property to show/hide the black border in a grid. If you want to format the currentcell, you need to handle the PrepareviewStyleInfo event.

this.grid.Model.Options.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;

//PrepareViewStyleInfo event.
GridCurrentCell cc = this.Grid.CurrentCell
if(e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex)
e.Style.Border.All = new GridBorder(GridBorderStyle.Solid,Color.Red);

Please let me know if this does not handle things for you,

Best Regards,
Haneef


DH David Hook October 27, 2006 10:36 AM UTC

Hi Haneef

Perfect! Thanks very much for your help.

Best Regards,

David

Loader.
Live Chat Icon For mobile
Up arrow icon