We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Lock somes cells

Thread ID:

Created:

Updated:

Platform:

Replies:

78006 Nov 25,2008 06:22 AM Nov 28,2008 06:09 AM WPF 3
loading
Tags: GridControl
Lionel Thiebaut
Asked On November 25, 2008 06:22 AM

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


Administrator [Syncfusion]
Replied On November 25, 2008 07:29 AM

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

Lionel Thiebaut
Replied On November 28, 2008 05:49 AM

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

Administrator [Syncfusion]
Replied On November 28, 2008 06:09 AM

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;
}
}
}
}
}
}



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;