It is only few days earlier I had posted an entry about disabling right click in a TextBox. Now how we do the same in DataGrid ?
It doesn’t seem quite as easy as in case of TextBox. The idea in assigning ContextMenu to DataGrid backfires when you attempt to right click right inside a cell. Thanks to my friend Justin Jose, I do have the solution for it.
DataGridTextBoxColumn dgColumn = new DataGridTextBoxColumn();
dgColumn.TextBox.ContextMenu = contextMenu1;
dgColumn.MappingName = "ColumnName";
DataGridTableStyle dgTableStyle = new DataGridTableStyle();
dgTableStyle.GridColumnStyles.Add(dgColumn);
myDataGrid.TableStyles.Add(dgTableStyle)
Thanks Justin, this is cool