This is a migrated thread and some comments may be shown as answers.

Four checkbox in radtreeview

6 Answers 182 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gabriele
Top achievements
Rank 1
Gabriele asked on 07 Feb 2012, 01:20 PM
Hi all,

I would like to manage 4 checkbox in my radtreeview.
Here's the code :


<telerik:RadTreeView ID="rtv" Height="250px" Width="350px" BorderStyle="Solid" BorderWidth="2px" BorderColor="Black" runat="server" 
Font-Names="Calibri" Font-Size="10px" CheckBoxes="true" CheckChildNodes="true" TriStateCheckBoxes="True">   
<NodeTemplate>
<asp:Label ID="lbl_equipe" Width="100px" Font-Size="10px" runat="server"><%# DataBinder.Eval(Container.DataItem, "EQUIPE")%></asp:Label>
<asp:CheckBox onclick="return false;" Text="I" Font-Size="8px" TextAlign="Left" Checked="false" ID="primo_operatore" runat="server"/>
<asp:CheckBox onclick="return false;" Text="II" Font-Size="8px" TextAlign="Left" ID="secondo_operatore" runat="server"/>
<asp:CheckBox onclick="return false;" Text="III" Font-Size="8px" TextAlign="Left" ID="terzo_operatore" runat="server"/>
</NodeTemplate>
</telerik:RadTreeView>

One checkbox is the built-in checkbox (CheckBoxes="true")
The other three cbx are inside nodetemplate.
I want to achieve two goals :
1. When user check (uncheck) the native checkbox the remaining three are checked (unchecked) goal achieved

2. When user check/uncheck one of the three template checkboxes nothing should happen..problem

I use the nodecheck event handler to get first goal (in code behind)
This event fires not just for the native checkbox but even for the remaining three!
How can I distinguish the element in order to prevent the nodecheck event  for the template checkboxes and let it fire for the single 
one ?
I've tried in code behind inside the event routine but the e.node is referred to the whole nodetemplate and I can't get the single elements in.
Here's my code:

 Private Sub rtv_NodeCheck(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles rtv.NodeCheck


        Dim chk1 As CheckBox = DirectCast(e.Node.FindControl("primo_operatore"), CheckBox)
        Dim chk2 As CheckBox = DirectCast(e.Node.FindControl("secondo_operatore"), CheckBox)
        Dim chk3 As CheckBox = DirectCast(e.Node.FindControl("terzo_operatore"), CheckBox)

'Code to prevent the event if sender is one of three checkbox NodeCheck 
' (??????????????????????????????????)

        If e.Node.Level <> 1 Then Exit Sub 'event just for level 1 nodes


        'parent nodes loop
        For Each nd As RadTreeNode In rtv.Nodes


            'When parent node is checked then start looping through all parent nodes looking for same nodetext
'If same node text is found then its checkbox is checked
           
            If e.Node.Checked = True Then


                'Enable node-template checkboxes
                DirectCast(e.Node.FindControl("primo_operatore"), CheckBox).Checked = True
                DirectCast(e.Node.FindControl("secondo_operatore"), CheckBox).Checked = True
                DirectCast(e.Node.FindControl("terzo_operatore"), CheckBox).Checked = True

'Child nodes loop
                For Each sub_nd As RadTreeNode In nd.Nodes
                    If sub_nd.Checked = False Then
                        Dim txt As String = sub_nd.Text 
                        If txt = e.Node.Text Then 'Node text comparison
                            sub_nd.Checked = True
                            sub_nd.ParentNode.Expanded = True

'For each parent node checked the checkboxes inside template-childnode are checked
                            DirectCast(sub_nd.FindControl("primo_operatore"), CheckBox).Checked = True
                            DirectCast(sub_nd.FindControl("secondo_operatore"), CheckBox).Checked = True
                            DirectCast(sub_nd.FindControl("terzo_operatore"), CheckBox).Checked = True


                        End If
                    End If
                Next


            Else
                'When parent node is unchecked then start looping through all parent nodes looking for same nodetext
'If same node text is found then its checkbox is unchecked


                'Disable node-template checkboxes
                DirectCast(e.Node.FindControl("primo_operatore"), CheckBox).Checked = False
                DirectCast(e.Node.FindControl("secondo_operatore"), CheckBox).Checked = False
                DirectCast(e.Node.FindControl("terzo_operatore"), CheckBox).Checked = False

'Child nodes loop
                For Each sub_nd As RadTreeNode In nd.Nodes
                    If sub_nd.Checked = True Then
                        Dim txt As String = sub_nd.Text
                        If txt = e.Node.Text Then
                            sub_nd.Checked = False
                            sub_nd.ParentNode.Expanded = False

'For each parent node unchecked the checkboxes inside template-childnode are unchecked
                            DirectCast(sub_nd.FindControl("primo_operatore"), CheckBox).Checked = False
                            DirectCast(sub_nd.FindControl("secondo_operatore"), CheckBox).Checked = False
                            DirectCast(sub_nd.FindControl("terzo_operatore"), CheckBox).Checked = False
                        End If
                    End If
                Next
            End If
        Next

    End Sub

English is not my language, hope I was understandable.
Thanks in advance

GZ

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Feb 2012, 02:47 PM
Hello,

I have tried to reproduce the issue but no avail. NodeCheck event only fires when the user checks or un-checks a Node checkbox,not fired for NodeTemplate CheckBoxes,that is the default behavior of RadTreeView.

Thanks,
Princy.
0
Gabriele
Top achievements
Rank 1
answered on 07 Feb 2012, 06:33 PM
Hallo Princy,

      thanks for replying, you're very kind

If it was as you stated I would not have reported my "issue".. ;-)
I put a BP on event NodeCheck and I can see the break when I check both the node checkbox or one of the three NodeTemplate CheckBoxes.. I thought it was the normal behaviour..

Thanks, let me know please

GZ

0
Gabriele
Top achievements
Rank 1
answered on 07 Feb 2012, 11:24 PM
Hi Princy,

   you were absolutely right !
   First I have to tell you (I forgot before..) that radtreeview is in a contentpage inside a masterpage.
   In this case I can confirm that nodecheck fires even with nodetemplate checkboxes
  
So I've tried to move all mark up and code behind in a non master page (a single aspx webform) and it behaves as expected
(nodecheck just for main node checkbox)

Is it an issue ? May you help me ? Other contentpages inside same masterpage work correctly.
Thanks

GZ
0
Gabriele
Top achievements
Rank 1
answered on 07 Feb 2012, 11:41 PM
Hi again,

after several attempts I got it !
The problem is radformdecorator. Never mind whether radtreeview is in masterpage or not. The following code :
 <telerik:RadFormDecorator ID="rfd" DecoratedControls="All" runat="server" /> is the reason why  node template checkboxes fire
the nodecheck event.
Were you aware of this ?
How can I fix it without give up the radformdecorator ?

Thanks again 

GZ
0
Bozhidar
Telerik team
answered on 10 Feb 2012, 09:53 AM
Hello Gabriele,

You can hook on the OnClientNodeChecking event and check where it originates from. If a checkbox from the template caused it, then you can cancel the event. Here's an example:
function clientNodeChecking(sender, args) {
    var target = args.get_domEvent().target;
    if (!$telerik.$(target).hasClass('rtChk')) {
        args.set_cancel(true);
    }
}

 
All the best,
Bozhidar
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Gabriele
Top achievements
Rank 1
answered on 10 Feb 2012, 03:33 PM
Thanks Bozhidar for reply,

  you propose to fix the problem downstream, acting directly on event. I'll try your solution as soon as possible.

However I found the upstream problem is RadFormDecorator. I found this issue described on web :

"This happens in some scenarios because of the way RadFormDecorator styles checkboxes - real checkboxes are hidden outside of the viewport. When the decorated checkbox is clicked however, browsers try to focus the real checkbox, hence the "jumping". To avoid that, you should set position:relative to the parent container"

This is strictly an IE issue. Indeed I tried with Chrome and firefox without any problem (no NodeCheck event at all) !
I don't know how to apply in my case the above solution. It could be useful in the future..

Thanks again, 

Gabriele
Tags
TreeView
Asked by
Gabriele
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gabriele
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or