In my syncfusion grid, I have to make some series cells non-editable based on the type. If the type is an 'XXX' then the cell is editable, If the type is a 'YYY','ZZZ' then cell is non-editable
So here;'s what I did.
private void theGrid_CurrentCellChanging(object sender, System.ComponentModel.CancelEventArgs e)
{
fp_data_typ typ;
int nSeries = theData.GetNumSeries();
for (int i = 0; i < nSeries; i++)
{
typ = theData.CheckType(i);
if (!(typ == 'XXX'))
{
e.Cancel = true;
}
}
}
I am not sure if I should be using theGrid_CurrentCellChanging event or theGrid_CurrentCellStartEditing. Documentation is not very clear. Gives me a ton of events to handle cell edit.
The code earlier works in an incorrect way. It does not work if the grid has a combination of editable and non-editable series. i:e if it has both xxx)editable and 'yyy'(non-editable), it makes both non-editable.
I was able to get the column index of the current cell and from there set e.cancel to true/false. Instead of setting e.cancel for the whole grid once, I went for the cell being edited.
Below events will help you to achieve your requirement.
//Use this if you want to control the ReadOnly setting while loading itself
grid.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo);
void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.Style.CellValue.Equals("YYY"))
{
e.Style.ReadOnly = true;
}
}
//Use this if you want to Validate while Editing
grid.CurrentCellValidating += new CurrentCellValidatingEventHandler(grid_CurrentCellValidating);
void grid_CurrentCellValidating(object sender, CurrentCellValidatingEventArgs e)
{
//Will deactive the cell and new value will be discarded
//e.NewValue = e.OldValue;
//To remain in Edit mode without committing the vlaue
e.Cancel = true;
}
Thanks, Sivakumar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.