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

cancel mouse click after the use of the context menu

Hello, 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, Sebastien private void cm_ListChanged(object sender, ListChangedEventArgs e) { if( e.ListChangedType == ListChangedType.ItemAdded ) { grid.Refresh(); grid.Focus(); 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(); dataTable.Rows.Add(dr); ((IBindingList)cm.List).ListChanged -= new ListChangedEventHandler(cm_ListChanged); return dr; } grid.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left | MouseButtons.Right;

1 Reply

AD Administrator Syncfusion Team June 24, 2005 01:45 PM UTC

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.

Loader.
Live Chat Icon For mobile
Up arrow icon