DevExpress依據前提設置GridControl RepositoryItem能否可編纂。本站提示廣大學習愛好者:(DevExpress依據前提設置GridControl RepositoryItem能否可編纂)文章只能為提供參考,不一定能成為您想要的結果。以下是DevExpress依據前提設置GridControl RepositoryItem能否可編纂正文
本文實例展現了DevExpress依據前提設置GridControl RepositoryItem能否可編纂的辦法。
普通在C#項目標開辟中,其實不是每一個RepositoryItem都可以編纂,常常是有前提性的,須要比方當A列等於“AA”的時刻,B列才可編纂,完成起來在ShowingEditor事宜中最為便利,而且參加toolTip提醒顯得人道化。
重要功效代碼以下:
private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { GridView _view = sender as GridView; if (_view.FocusedColumn.Name == "colSavePowerGp1")//當列等於colSavePowerGp1 { string _type = _view.GetRowCellDisplayText(gvLampConfig.FocusedRowHandle, "OptStatusText_gp1"); if (!_type.Equals("節能"))//當列OptStatusText_gp1的列值不等於OptStatusText_gp1 { e.Cancel = true; ShowToolTip(toolTipController, "提醒", "當是【調光狀況】是節能形式情形,可以設置該值!"); } } } public static void ShowToolTip(ToolTipController toolTip, string title, string content) { Point _mousePoint = Control.MousePosition; toolTip.ShowHint(content, title, _mousePoint); }
代碼運轉後果以下:
為了調高代碼復用性,便利後續應用,可以如許子封裝一下:
/// <summary> /// 設置RepositoryItem能否可編纂 /// 解釋: /// 在ShowingEditor事宜中應用 /// </summary> /// <param name="view">GridView</param> /// <param name="focusedColumnName">須要設置的列稱號</param> /// <param name="conditonHanlder">斷定拜托</param> /// <param name="toolTip">ToolTipController</param> /// <param name="title">當前提拜托成立的時刻提醒題目</param> /// <param name="content">當前提拜托成立的時刻提醒內容</param> /// <param name="e">CancelEventArgs</param> private void CustomShowingEditorWithToolTip(GridView view, string focusedColumnName, Func<object, bool> conditonHanlder, ToolTipController toolTip, string title, string content, CancelEventArgs e) { if (view.FocusedColumn.Name.Equals(focusedColumnName)) { if (conditonHanlder(view.GetFocusedRow())) { e.Cancel = true; Point _mousePoint = Control.MousePosition; toolTip.ShowHint(content, title, _mousePoint); } } }
代碼應用以下:
private void gvLampConfig_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { GridView _view = sender as GridView; CustomShowingEditorWithToolTip(_view, "colSavePowerGp1", arg => ((LampSelfRunCfgParamter)arg).OptStatusText_gp1 != "節能", toolTipController, "提醒", "當是【調光狀況】是節能形式情形,可以設置該值!", e); }
願望本文所示代碼能對年夜家有所贊助!