Reputation: 21
I'm using a Sourcegrid.DataGrid with a selection mode set to
this.dataGrid1.SelectionMode = SourceGrid.GridSelectionMode.Row;
and I need to disable from editing (with double click) a single cell.
I know how to disable an entire Column using
this.dataGrid1.Columns[0].DataCell.Editor.EnableEdit = false;
But I don't know how to disable a single cell.
Can someone explain how to do, please?
Upvotes: 1
Views: 2608
Reputation: 21
Thank you to Marek for your effort, but your solution is for another .net control.
I have found myself a workaround to solve the problem. I think that there is a bug on the control that avoid to disable a single cell (or I haven't found the right solution to do this).
If I have a cell with a fixed/pre-defined text, I can block editing with the following code
private void dataGrid1_DoubleClick(object sender, EventArgs e)
{
SourceGrid.DataGrid dg = (SourceGrid.DataGrid)sender;
//Get the position of the clicked cell
int c = dg.MouseCellPosition.Column;
int r = dg.MouseCellPosition.Row;
//create a Cell context
SourceGrid.CellContext cc = new SourceGrid.CellContext(dg, new SourceGrid.Position(r,c));
//and retrieve the value to be compared with a pre-defined text
if (String.Compare(cc.DisplayText, "SOMETEXT") == 0)
this.dataGrid1.GetCell(r, c).Editor.EnableEdit = false; //Disable the editing
else
this.dataGrid1.GetCell(r, c).Editor.EnableEdit = true; //Enable the editing
}
I hope this can help someone.
Regards,
Alex
Upvotes: 1