KB Article A2815
Visible to All Users

How to display disabled buttons for particular cells within a ButtonEdit column

Description:
I want to display disabled buttons in a ButtonEdit column for a particular cell depending upon some condition. How can I do this?

Answer:
There are three ways to implement this task:

  1. Create two ButtonEdit repository items. One with the enabled button and another with the disabled button. Then handle the GridView.CustomRowCellEdit event and pass the necessary repository item to the e.RepositoryItem parameter according to a specific condition. Please see the Assigning Editors to Individual Cells help topic for additional information.
    2. Create a custom button editor. (Custom editor creation is described in the Custom Editors article.) Then, implement a custom ViewInfo class and override the OnBeginPaint()  method as shown below.
C#
public class CustomButtonEditViewInfo : ButtonEditViewInfo { protected override void OnBeginPaint() { base.OnBeginPaint(); ApplyState(); } public void ApplyState() { ButtonStateEventArgs e = new ButtonStateEventArgs(Tag); (this.Item as RepositoryItemCustomButtonEdit).RaiseButtonStateEvent(e); if (!e.IsEnable && this.RightButtons.Count > 0) { this.RightButtons[0].State = DevExpress.Utils.Drawing.ObjectState.Disabled; } } public CustomButtonEditViewInfo(RepositoryItem item) : base(item) { } }
Visual Basic
Public Class CustomButtonEditViewInfo Inherits ButtonEditViewInfo Protected Overrides Sub OnBeginPaint() MyBase.OnBeginPaint() ApplyState() End Sub Public Sub ApplyState() Dim e As New ButtonStateEventArgs(Tag) TryCast(Me.Item, RepositoryItemCustomButtonEdit).RaiseButtonStateEvent(e) If (Not e.IsEnable) AndAlso Me.RightButtons.Count > 0 Then Me.RightButtons(0).State = DevExpress.Utils.Drawing.ObjectState.Disabled End If End Sub Public Sub New(ByVal item As RepositoryItem) MyBase.New(item) End Sub End Class

Additionally, implement the GetButtonState event in a custom RepositoryItem class. Handle it to pass any custom condition to the editor.
Please see the How to display disabled buttons for particular cells within a ButtonEdit column example (or attached example) to get a detailed solution.
See Also:
How to Conditionally Prevent Editing for Individual Grid Cells
How to customize the Look-And-Feel of my grid cells
How to make my grid columns read-only
How to change the editor's button text depending upon the grid row

Show previous comments (5)
DevExpress Support Team 11 years ago

    Hi Carole,
    To process your inquiry in the most efficient manner, I've created a separate ticket on your behalf:
    How to display ButtonEdit with disabled buttons for particular cells
    Please refer to it for further correspondence.

    M M
    Michael Proctor [DX-Squad] 6 years ago

      This link at the end of the article seems to be to an internal system?

      http://isc.devexpress.com/Thread/WorkplaceDetails/T100881

      I am interested to see the example regarding creating a GetButtonState event, I already have a inherited ButtonEdit and ViewInfo as I have implemented the ability to not have the buttons stretch the entire width of the editor using another example.

      What I am trying to work out is that during the GetButtonState event of the RepositoryItem how would you get the current row information.

      DevExpress Support Team 6 years ago

        Hello Michael,
        Thank you for informing us about this issue. I've updated the link in the article so now you can refer to this example.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.