Hi,
I have a grid which display a AddNewRow row on the top of the grid to add a new row to the grid. Once of the column of the new row is a drop down so that user is restricted to select value from the list. My requirement is once the row is added the column with drop down should be not editable.
I have done few thing but not a perfect solution,
in the InitializeLayout method I set the column style as DropDownList and set it ValueList. and then in BeforeRowActivate method i added following code.
if (e.Cell.Row.IsAddRow) { e.Cell.Row.Cells["COL_VLIST"].Activation = Activation.AllowEdit; } else { e.Cell.Row.Cells["COL_VLIST"].Activation = Activation.NoEdit; }
Another approached I used is in AfterRowInsert method I set the Cell ValueList, but it retain this valuelist after row is added to the grid?
What is the best way to handle this situation? Also another issue is when I am entering value in the new row anc click the down arrow the row is added to the grid, is there way so that I can validate teh value before row is added to the grid?
It looks like InitializeRow isn't fire again when the row is committed. So you probably have to handle AfterRowUpdate and set the cell activation property there, also. Since the row will never be an add row after it has been updated, you don't even need to check anything, you can just also mark the cell as NoEdit inside AfterRowUpdate.
Mike,
In the InitializeRow event if I set the CellActivation for the row to "NoEdit" that's works for existing row but when I add a new row then the new row once added to the grid have it CellActivation set to Editable (basically user can change the value of the drop down column), which I want to avoid. Please advise.
I'm not sure I understand what you are asking.
If you want the cell to be editable in the AddRow, but not in any other rows, then it seems like you should be able to handle this in the InitializeRow event and you don't really need any other event handlers.
dverma said:Another approached I used is in AfterRowInsert method I set the Cell ValueList, but it retain this valuelist after row is added to the grid?
I can't see any reason why the cell would not maintain the ValueList. But I don't think this is a good approach. It would be better to assign the ValueList to the column. This is especially important if the field is a key field where you are translating the data value into some display text.
dverma said:What is the best way to handle this situation? Also another issue is when I am entering value in the new row anc click the down arrow the row is added to the grid, is there way so that I can validate teh value before row is added to the grid?
I don't understand. Do you mean the dropdown button? Or the down arrow on the keyboard?
Neither of these should be adding a new row to the grid.