//Event Subscription
sfDataGrid.SelectionChanging += OnSelectionChanging;
sfDataGrid.TableControl.MouseClick += OnMouseClick;
sfDataGrid.CellCheckBoxClick += OnCellCheckBoxClick;
//Event Customization
private void OnCellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e)
{
//Here customize based on your scenario
if(isCheckBoxCellClicked)
{
//Here handle check or uncheck state of checkbox
e.Cancel = true;
//Here reset the boolean value
isCheckBoxCellClicked = false;
}
}
//here maintain the boolean value to only show the context menu
on right click
bool isCheckBoxCellClicked;
private void OnMouseClick(object sender, MouseEventArgs e)
{
//Here customize based on your scenario
// get the row and column index based on the pointer position
var rowColIndex =
sfDataGrid.TableControl.PointToCellRowColumnIndex(e.Location);
//Check the condition is AddNewRow and Only show the context
menu while pressing right button of Mouse
if (e.Button == MouseButtons.Right &&
sfDataGrid.Columns[rowColIndex.ColumnIndex].MappingName == "IsShipped" &&
!rowColIndex.IsEmpty)
{
//here enable the boolean proeprty only for GridCheckboxColumn
isCheckBoxCellClicked = true;
}
}
private void OnSelectionChanging(object sender, SelectionChangingEventArgs e)
{
//Here customize based on your scenario
if (isCheckBoxCellClicked)
{
//Here handle the Selection when right click on checkbox
e.Cancel = true;
}
}
|