Home - Forums-.NET - FlyTreeView (ASP.NET) - Checkbox Changed Event

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Checkbox Changed Event
Link Posted: 12-Apr-2007 03:38
I need to find a way to trap when the user toggles Check Box Client side, both true and false and then fire a VB handler in my code behind of some sort (so I can call a SQL SP and change the underlying data)

Failing that I need to capture the entire node collection so that I can itererate through them. It's no problem for checked nodes but I'm having trouble for unchecked. (which I had with ms treeview and why I'm liking the look of FlyTreeView)

And ... last but not least I need to do this with the Item ID field (which is what I used to create the node in the ConvertTabularDataToHierarchical function but seems to disappear after. I guess I have to create an attribute to carry this value?

My strength is the VB / SQL side. My Java is week so please be explict if you have a solution

I can't believe this isn't a pretty common requirment ... can anyone help?
Link Posted: 12-Apr-2007 07:38
[quote="gonewalkabout"]I need to find a way to trap when the user toggles Check Box Client side, both true and false and then fire a VB handler in my code behind of some sort (so I can call a SQL SP and change the underlying data)

Failing that I need to capture the entire node collection so that I can itererate through them. It's no problem for checked nodes but I'm having trouble for unchecked. (which I had with ms treeview and why I'm liking the look of FlyTreeView)

So do you just need to get unchecked nodes at server side? Something similar to FlyTreeView.GetCheckedNodes() but to look like FlyTreeView.GetUncheckedNodes()?
Or do you need to handle client-side checked/unchecked event?

[quote="gonewalkabout"]
And ... last but not least I need to do this with the Item ID field (which is what I used to create the node in the ConvertTabularDataToHierarchical function but seems to disappear after. I guess I have to create an attribute to carry this value?

You can set a binding containing binding.ValueField = "ID". So flytreeview will pick up your ID  into node.Value property during data binding process.
Link Posted: 12-Apr-2007 08:31
On the checked nodes question ...Either will do. I know I have the FlyTree.GetCheckedNodes collection and the same thing for unchecked would work OK.

what I'd prefer to do is create a collection of ALL nodes in the tree and then as I iterate through them pick up the checked/unchecked state.

Thanks for the answer in the Binding=ID ... I figured it was somehting like that but the issue above is what will make or break my going forward with this control.

Thanks again
Link Posted: 12-Apr-2007 09:34
To return all the nodes of FlyTreeView you can use FindAll(predicate) method. In your case predicate should always return true.

For VB.NET:

yourCollection = treeview.FindAll(AddressOf FindPredicate)

and there should be defined some function with the condition predicate

Private Shared Function FindPredicate(ByVal node As FlyTreeNode) _
        As Boolean
        Return True
End Function

So now you have all nodes of treeview matching condition which in your case always return True (all nodes).
Link Posted: 13-Apr-2007 23:02
I had managed to get a recursive walkthrough  working starting at the '0' item and doing all kinds of wacky back and forth. Probably 75 lines of code. You have replaced it with 2 (and I suspect it's way safer thenmine).  

So to recap for anyone else facing the same problem:
In an event handler (I used the button click after I have checked and unchecked the tree)

Dim nodes As FlyTreeNodeCollection = FlyTree.FindAll(AddressOf FindPredicate)

Then the function:
    Private Shared Function FindPredicate(ByVal node As FlyTreeNode) As Boolean
        Dim dbCon As SqlConnection
        dbCon = New SqlConnection(ConfigurationManager.ConnectionStrings(\"HellyReportMgrConnectionString\").ConnectionString)

        Dim cmd_sp As New SqlCommand(\"ReportObjectsHide\", dbCon)
        cmd_sp.CommandType = CommandType.StoredProcedure
        dbCon.Open()
        cmd_sp.Parameters.Add(New SqlParameter(\"@ItemID\", SqlDbType.NVarChar, 1000)).Value = node.Value
        cmd_sp.Parameters.Add(New SqlParameter(\"@Checked\", SqlDbType.Bit)).Value = node.Checked
        cmd_sp.ExecuteNonQuery()
        cmd_sp.Parameters.Clear()
        dbCon.Close()

        Return True
    End Function

I'm using a sql sp here but couple with the client side check box advanced stuff in one of the demos this method makes sure your 'child' nodes always have parents (which is about the easiest way to break this kind of data call)