Ticket Q394009
Visible to All Users

ASPxTreeList - How to disable a checkbox for the node selection

created 13 years ago

How can we achieve the same functiolnality described in http://www.devexpress.com/Support/Center/p/Q239346.aspx in this version of control?
i.e. we need to disable the checkboxes but preserve their visibility and value.
Thanks Graziano Tona

Answers

created 13 years ago

Hi Antonio,
Thank you for the question. ASPxTreeList does not provide a capability to disable an internal checkbox. I have created a corresponding suggestion (S39376 - ASPxTreeList - Provide the capability to disable/enable a check box for node selection). Please track it to be notified of our project.
A possible solution to the issue is to place ASPxCheckBox to the DataCell template of the required column. In the ASPxCheckBox.Init event handler, subscribe to the ASPxClientCheckBox.CheckedChanged event. In this event handler, select/deselect a node via the ASPxClientTreeList.SelectNode method.
Attached is a sample project that demonstrates how you accomplish this task.
Thanks,
Nikolai

    Comments (2)

      Thanks for your replay.
      It is a bit confusing to know that a feature is no more available. We have some projects ported to the latest version of your components that need to be recoded with the workaround you suggested.
      Anyway the solution given is not applicabile totally in our case here th code we used:
      This is the code that works:
       Protected Sub OnCheckBoxInit(ByVal sender As Object, ByVal e As EventArgs)
                  Dim chk As CheckBox = TryCast(sender, CheckBox)
                  Dim container As TreeListDataCellTemplateContainer = TryCast(chk.NamingContainer,TreeListDataCellTemplateContainer)
                  Dim node As TreeListNode = ASPxTreeListPopUp.FindNodeByKeyValue(container.NodeKey)
                  If node.Selected Then
                      chk.Checked = True
                  End If
                  If node.Item("abilitato") <> "0" Then
                      chk.Attributes("onclick") = String.Format("OnCheckedChanged({0});", container.NodeKey)
                  Else
                      chk.Enabled = False
                  End If
              End Sub
      This is your code modified that doesn't work (the checked property is ignored).As stated in my original question we need also to modify the value and set it if needed.
      Protected Sub OnCheckBoxInit(ByVal sender As Object, ByVal e As EventArgs)
                  Dim chk As ASPxCheckBox = TryCast(sender, ASPxCheckBox)
                  Dim container As TreeListDataCellTemplateContainer = TryCast(chk.NamingContainer, TreeListDataCellTemplateContainer)
                  Dim node As TreeListNode = ASPxTreeListPopUp.FindNodeByKeyValue(container.NodeKey)
                  If node.Selected Then
                      chk.Checked = True ' IS INGNORED
                  End If
                  If node.Item("enabled") <> "0" Then
                      chk.ClientSideEvents.CheckedChanged = String.Format("function(s, e) {{ OnCheckedChanged(s, e, {0}) }}", container.NodeKey)
                  Else
                      'disable checkbox via the chk.ClientEnabled = false
                      chk.ClientEnabled = False
                  End If
              End Sub
      In my humble opinion the new ASPXCheckbox need a review (seem buggy).
      Thanks for attention

      DevExpress Support Team 13 years ago

        Hi Antonio,
        I've tried to run the project provided by Nikolai and it works properly here. Here is the code I used to test:

        Visual Basic
        Protected Sub OnCheckBoxInit(ByVal sender As Object, ByVal e As EventArgs) Dim chk As ASPxCheckBox = TryCast(sender, ASPxCheckBox) Dim container As TreeListDataCellTemplateContainer = chk.NamingContainer chk.ClientEnabled = Convert.ToInt32(container.NodeKey) Mod 2 = 0 chk.Checked = chk.ClientEnabled chk.ClientSideEvents.CheckedChanged = String.Format("function(s, e) {{ OnCheckedChanged(s, e, {0}) }}", container.NodeKey) End Sub

        I also do not quite understand why you need to check checkBoxes programmatically in the editor's Init event handler. The editor's state are correctly preserved during the round trip to the server.
        Thanks,
        Plato

        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.