2

グリッドの編集時に他の変更可能な間に読み取り専用でなければならない機能を実現するmvcデベロッパーグリッドがあります。新しい列を追加するには、前に述べた読み取り専用列を含めてすべての列を変更可能にする必要があります。設定を使用します。グリッド全体ではなく特定の列にセルエディタを初期化します。

これは、グリッド

@{ 

    var grid = Html.DevExpress().GridView(settings => 
    { 
     settings.Name = "GridViewDuration"; 
     settings.CallbackRouteValues = new { Controller = "DurationMaster", Action = "GridViewDurationPartial" }; 

     settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction1" }; 
     settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction2" }; 
     settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction3" }; 
     settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow; 
     settings.SettingsBehavior.ConfirmDelete = true; 

     settings.CommandColumn.Visible = true; 
     settings.CommandColumn.ShowNewButton = true; 
     settings.CommandColumn.ShowDeleteButton = true; 
     settings.CommandColumn.ShowEditButton = true; 

     settings.KeyFieldName = "DurationId"; 

     settings.SettingsPager.Visible = true; 
     settings.SettingsPager.PageSize = 20; 
     settings.Settings.ShowGroupPanel = true; 
     settings.Settings.ShowFilterRow = true; 
     settings.SettingsBehavior.AllowSelectByRowClick = false; 
     settings.Columns.Add(column => 
     { 
      column.FieldName = "Column1"; 
      column.ReadOnly = true; 
      column.Width = 20; 

     }); 
     settings.Columns.Add(column => 
     { 
      column.FieldName = "Column2"; 
      column.Caption = "xyz"; 
      column.ColumnType = MVCxGridViewColumnType.ComboBox; 
      column.Width = 250; 

      var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties; 
      comboBoxProperties.DataSource = PMC.Web.Controllers.DurationMasterController.getSelectList("0", "MyAction4"); 
      comboBoxProperties.TextField = "Text"; 
      comboBoxProperties.ValueField = "Value"; 
      comboBoxProperties.ValueType = typeof(int); 
      comboBoxProperties.ValidationSettings.RequiredField.IsRequired = true; 


     }); 
     settings.InitNewRow = (sender, e) => 
     { 
      e.NewValues["ColumnId"] = 0; 
     }; 
     settings.Columns.Add("ColumnName"); 
     settings.Columns.Add("Description"); 
     //settings.Columns.Add("DisplayName"); 
     settings.Columns.Add(column => 
    { 
     column.Caption = "FromDate"; 
     column.FieldName = "FromDate"; 
     column.ColumnType = MVCxGridViewColumnType.DateEdit; 
     column.ReadOnly = true; 
     var DateEditProperties = column.PropertiesEdit as DateEditProperties; 
     column.CellStyle.Wrap = DefaultBoolean.False; 
    }); 



    settings.Columns.Add(column => 
    { 
     column.Caption = "ToDate"; 
     column.FieldName = "ToDate"; 

     column.ColumnType = MVCxGridViewColumnType.DateEdit; 
     var DateEditProperties = column.PropertiesEdit as DateEditProperties; 
     column.CellStyle.Wrap = DefaultBoolean.False; 
    }); 
    }); 
    if (ViewData["EditError"] != null) 
    { 
     grid.SetEditErrorText((string)ViewData["EditError"]); 
    } 

} 
@grid.Bind(Model).GetHtml() 

ための私のコードであり、これは私が唯一のfromDate列を必要としながら、これは、読み取り専用で、すべてのグリッド列を設定します

settings.CellEditorInitialize += (s, e) => 
     { 
      var abc = s as ASPxGridView; 
      e.Editor.ReadOnly = !abc.IsNewRowEditing; 
     }; 

を試みたものですbe readonly

助けていただければ幸いです。ありがとう。

答えて

2

は、代わりにあなたの目的の列

にCellEditorInitializeイベントを使用することができます
settings.CellEditorInitialize += (s, e) => 
{ 
    var abc = s as ASPxGridView; 
    if (e.Column.FieldName == "YourFieldName") 
     e.Editor.ReadOnly = !abc.IsNewRowEditing; 
}; 
0

まだ動作をセットアップする必要があると私は考えていますMVCxGridViewColumn.SetEditItemTemplateContentその特定の列に。

これはあなたのプレビュー1に非常に同様の問題です、

Set ReadOnly property to a column of devexpress grid(MVC) only on edit click

次の解決方法を試してみてくださいそれが必要な作品:

settings.Columns.Add(col => 
    { 
     col.FieldName = "FromDate"; 
     col.Caption = "From Date"; 
     col.Width = Unit.Percentage(15); 
     col.ColumnType = MVCxGridViewColumnType.DateEdit; 

     col.SetEditItemTemplateContent(e => 
     { 
      var fromDate = DateTime.Now; 

      ViewContext.Writer.Write(
       Html.DevExpress().DateEdit(settingsDateEdit => 
       { 
        settingsDateEdit.Name = "fromDate"; 
        settingsDateEdit.Width = Unit.Percentage(100); 

        settingsDateEdit.ReadOnly = !e.Grid.IsNewRowEditing; 

       }).Bind(fromDate).GetHtml() 
      ); 
     }); 
    });