Lock somes cells

Hi,
I have to lock some cells of my gridcontrol but not all them.
Into the cells which I have to lock, I don't want to :
- select their content,
- select cell
- have menu with Cut/Copy/Paste (is by default into my grid control but I don't want it).
And into the other cells I just want to have a contextmenu.

How is it possible ?

Thanks.
Lionel


3 Replies

AD Administrator Syncfusion Team November 25, 2008 12:29 PM UTC

Here is a little sample that uses a PreviewRighMouseDown event handler to control wehther certain cells have context menus or not. Column 1 shows no menu at all, column 2 shows a custom menu except for the cell in row 2 which shows no menu (and cannot be clicked or the text in it selected), and columns 3 and 4 show the default menu.

Cell 2,2 has its style.Enabled = false and style.CellType = "Static". This is why that cell cannot be clicked or the text in it selected.





ContextMenu1_b88e3bea.zip


LT Lionel Thiebaut November 28, 2008 10:49 AM UTC

Hi, I try what you say but the problem is always here.
I put the property CellType="Static" and Enabled=False.
You can see the print screen.
Thanks



pb_cells_4c089ba6.zip


AD Administrator Syncfusion Team November 28, 2008 11:09 AM UTC

If you do not want a cell to be part of a selected range of cells (this is different that not wanting to be able to select text in a cell), then you can handle the grid.Model.SelectionChanging event, and cancel it if you are trying to select a disabled cell. In the sample above, this event was already being handled for another reason. You can just add code to that handler to not select cells when the cell.Style.Enabled is false.

void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
//do not allow the selection to change on right mouse click
if (Mouse.RightButton == MouseButtonState.Pressed)
{
e.Cancel = true;
}

if (!e.Range.IsEmpty)
{
GridRangeInfo range = e.Range.ExpandRange(1, 1, grid.Model.RowCount, grid.Model.ColumnCount);
int row, col;
if (range.GetFirstCell(out row, out col))
{
GridStyleInfo style = grid.Model[row, col];
if (!style.Enabled)
{
e.Cancel = true;
}
else
{
while (range.GetNextCell(ref row, ref col))
{
style = grid.Model[row, col];
if (!style.Enabled)
{
e.Cancel = true;
break;
}
}
}
}
}
}



Loader.
Up arrow icon