[DevExpress Support Team: CLONED FROM E5116: ASPxGridView - How to make some field editors read-only when editing a row and allow their editing when adding a new row]
Hi, i have applied given example in ASP.NET MVC, folllwing is my gridview settings sample partial code:
C#settings.CellEditorInitialize = (s, e) =>
{
ASPxGridView grid = s as ASPxGridView;
ASPxEdit editor = (ASPxEdit)e.Editor;
if (e.Column.FieldName == "columnName1" || e.Column.FieldName == "columnName2")
{
e.Editor.ReadOnly = !grid.IsNewRowEditing;
}
};
now i can't edit while updating existing row data, that seems perfect.
but i can't edit both columns while creating new row using new button. please help me out here. Thank you in advance.
Hello,
I have created a sample using the provided snippet but the issue is not reproduced. See the attached screencast. Please send us a sample project for research or you can modify my project. This will allow us to find the cause of the issue faster.
hi Nataly,
Thanks a lot for your response and great support.
my problem is: its working fine when:
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow; //if we change editing mode to batch editng mode then this feature is not wokring. settings.SettingsEditing.Mode = GridViewEditingMode.Batch; settings.SettingsEditing.BatchEditSettings.EditMode = GridViewBatchEditMode.Row; settings.SettingsEditing.BatchEditSettings.StartEditAction = GridViewBatchStartEditAction.DblClick;
please help me out here, if you need a project sample, please let me know, i will upload a sample project where its not working in given case.
waiting for your response and my solution.
Hello,
If you are using the grid in Batch Edit Mode, this solution will not suit you. I suggest that you handle the ASPxClientGridView.BatchEditStartEditing event and analyze the grid's arguments. For example, you can determine if the editing operation is performed for an existing or new row by using visibleIndex (which is -1 for a new row).
function OnBatchEditStartEditing(s, e) { if ((e.focusedColumn.fieldName == "ProductName") && (e.visibleIndex >-1)) e.cancel = true; }
Attached is a screencast illustrating this solution in action. You can refer to the ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally example, which describes this approach in greater detail.
Let me know if you need further clarification regarding this.
Thank you so much Nataly, it worked as expected. :)