The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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;
ADAdministrator 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.