[Devexpress] condition setting: whether gridcontrol repositoryitem can be edited

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.