I am using the following code to add a row to a grid using a context menu and to give the focus on the first cell of the added row (even if the grid is sorted).
Well it works fine except when the user makes a right click to display the context menu on a cell of the grid. If there is no scroll at all when the new line is added then there is a click generated and the focused cell is the one on which the right click was made.
Is there a way to cancel the click generated after the user has choosen an item in the context menu?
Thanks in advance,
private void cm_ListChanged(object sender, ListChangedEventArgs e)
if( e.ListChangedType == ListChangedType.ItemAdded )
grid.CurrentCell.MoveTo( e.NewIndex+1, 1, GridSetCurrentCellOptions.ScrollInView );
public DataRow AddAndFocusDataRow(DataTable dataTable)
CurrencyManager cm = (CurrencyManager) grid.BindingContext[ dataTable ];
((IBindingList)cm.List).ListChanged += new ListChangedEventHandler(cm_ListChanged);
DataRow dr = dataTable.NewRow();
((IBindingList)cm.List).ListChanged -= new ListChangedEventHandler(cm_ListChanged);
grid.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left | MouseButtons.Right;
ADAdministrator Syncfusion Team June 24, 2005 08:45 AM
Is your context menu being displayed because you are setting the COntrol.ContextMenu property, or because you are catching the mouseclick and explcitly displaying a context menu.
If you are doing the latter and handling a grid event like CellClick to catch teh mouse action, then you can set e.Cancel to prevent further processing of the click.
But if you are relying on the ContextMenu property, then one solution would be to remove the MouseButtons.Right from the SelectCellsMouseButtonsMask property.