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
ASPxTreeList - How to disable a checkbox for the node selection
Answers
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
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
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 BasicProtected 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