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
close icon

To get current cell


Hi,
I want to get the current cell of the databoundgrid.
There is currentcell property which gives me current cell only if I click that cell. But if I click/rightclick on the fixed row/column I dont get the exact value. I get only the previous cell values.
Like suppose I click on the header whose rowindex is 0. then I should get the rowindex and column index of it. Is there any way I can get it.

Thanks,
Sandeep

4 Replies

SA Sandeep November 15, 2006 05:37 AM UTC


Hi,
I will tell you want I want to do.

I have attached context menu to the grid. But I want to display the context menu only if user clicks the cell and not the header or the left fixed column. Right now it displays context menu if I click anywhere on the grid.

Please provide me solution.

Thanks,
Sandeep


AD Administrator Syncfusion Team November 15, 2006 05:40 AM UTC

Hi Sandeep ,

By default, The current cell gets activated after clicking on it ( Because of the default ActivateCurrentCellBehavior property setting of the grid). If you want to set the currentcell as a clicked cell, you need to use the CurrentCell.MoveTo method in CellClick/CellDoubleClick event. Here is a code snippet.

//Cellclick event
this.grid.CurrentCell.MoveTo(e.RowIndex,e.ColIndex);

Best Regards,
Haneef


AD Administrator Syncfusion Team November 15, 2006 05:58 AM UTC

Hi Sandeep,

You can handle the MouseUp event of the GridControl and conditionally display a context menu for the grid cells. Here is a code snippet.

private void gridControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if( e.Button == MouseButtons.Right )
{
GridControl grid = sender as GridControl;
Point pt = new Point(e.X,e.Y);
int row,col;
grid.PointToRowCol(pt,out row,out col);
if(row > 0 && col > 0)
this.contextMenu1.Show(this.gridControl1,pt);
}
}

Sample : http://www.syncfusion.com/Support/user/uploads/contextmenu_2453f1f0.zip

Best Regards,
Haneef


SA Sandeep November 15, 2006 06:17 AM UTC

Hi Hanif,

Thank you very much. It solved my problem

Thanks,
Sandeep

Loader.
Live Chat Icon For mobile
Up arrow icon