During project development, not every repositoryitem can be edited. It is often conditional. For example, if column A is equal to column AA, column B can be edited, the implementation is the most convenient in the showingeditor event, and the tooltip is user-friendly.
The Code is as follows:
Private void gvlampconfig_showingeditor (Object sender, system. componentmodel. canceleventargs e) {gridview _ view = sender as gridview; If (_ view. focusedcolumn. name = "colsavepowergp1") // when the column is colsavepowergp1 {string _ type = _ view. getrowcelldisplaytext (gvlampconfig. focusedrowhandle, "optstatustext_gp1"); If (! _ Type. equals ("energy saving") // when the column value of optstatustext_gp1 is not equal to optstatustext_gp1 {e. cancel = true; showtooltip (tooltipcontroller, "prompt", "when the" dimming status "is the energy-saving mode, you can set this value! ") ;}} Public static void showtooltip (tooltipcontroller tooltip, String title, string content) {point _ mousepoint = control. mouseposition; tooltip. showhint (content, title, _ mousepoint );}
Code effect:
To improve code reusability and facilitate subsequent use, you can encapsulate the Code as follows:
/// <Summary> /// set whether repositoryitem can be edited. /// description: /// use it in the showingeditor event /// </Summary> /// <Param name = "View"> gridview </param> /// <Param name = "focusedcolumnname "> name of the column to be set </param> /// <Param name =" conditonhanlder "> delegate judgment </param> /// <Param name =" tooltip "> tooltipcontroller </param> /// <Param name = "title"> when the condition delegate is set up, the title is displayed. </param> /// <Param name = "content"> when the condition prompt content when the delegate is set up </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 );}}}
Code usage:
Private void gvlampconfig_showingeditor (Object sender, system. componentmodel. canceleventargs e) {gridview _ view = sender as gridview; customshowingeditorwithtooltip (_ view, "colsavepowergp1", Arg => (lampselfrunw.paramter) Arg ). optstatustext_gp1! = "Energy-saving", tooltipcontroller, "prompt", "when the [dimming status] is the energy-saving mode, you can set this value! ", E );}
Hope this is helpful!