Saturday, April 25, 2009

Disable Right Click in DataGrid , Thanks Justin

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();

Thanks Justin, this is cool