C# treeview Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fadah
    New Member
    • Mar 2008
    • 9

    C# treeview Forms

    Is there a way to list opend mdichild forms in treeview so i could open them while i click on treeview nodes with the form name.I allready got the way how i can get the opend mdichild forms to list in treeview, now i need to make a click event so selected node would open the selected form. How can i get that.

    Plz help ty.
  • Sick0Fant
    New Member
    • Feb 2008
    • 121

    #2
    Is the treeview in the MDI itself?

    Comment

    • fadah
      New Member
      • Mar 2008
      • 9

      #3
      treeview is in mdicontainer form the parent form.

      Comment

      • Sick0Fant
        New Member
        • Feb 2008
        • 121

        #4
        Well, since you create the windows in FrameWndProc() upon receiving a NEW_DOCUMENT message, it should be fairly easy to get the handles to those windows, shouldn't it?

        EDIT: I'm sorry, I was thinking C++ API.

        But... give me some time to think aboutthe .NET solution.

        Comment

        • fadah
          New Member
          • Mar 2008
          • 9

          #5
          Originally posted by Sick0Fant
          Well, since you create the windows in FrameWndProc() upon receiving a NEW_DOCUMENT message, it should be fairly easy to get the handles to those windows, shouldn't it?

          I dont understand what u mean :S

          anyway here is code that adds form names to treeview.

          Code:
                      for(int i = 1; i < this.MdiChildren.Length;i++)
                          {
                                  PrivMsg.Nodes.Clear();
                                  PrivMsg.Nodes.Add(this.MdiChildren[i].Name.ToString());
                          }
          Still havent figured it out :S plz help

          Comment

          • Sick0Fant
            New Member
            • Feb 2008
            • 121

            #6
            If you already have the nodes in the treeview, then it should fire an event everytime the user clicks on a different node. You don't need to create this event--it's fired automatically. You just need to handle it.

            Comment

            • balabaster
              Recognized Expert Contributor
              • Mar 2007
              • 798

              #7
              Originally posted by fadah
              I dont understand what u mean :S

              anyway here is code that adds form names to treeview.

              Code:
               for(int i = 1; i < this.MdiChildren.Length;i++)
              {
              PrivMsg.Nodes.Clear();
              PrivMsg.Nodes.Add(this.MdiChildren[i].Name.ToString());
              }
              Still havent figured it out :S plz help
              Before you add the node, I would pass i into the tag of that node, this way you can easily select the relevant MDI form when the node is selected instead of having to iterate through your forms looking for the one with the relevant name.

              VB
              Code:
              Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) _
                Handles TreeView1.AfterSelect
              	Dim oNode As TreeNode = TreeView1.SelectedNode
              	If (Not oNode Is Nothing) AndAlso (Not oNode.Tag Is Nothing) Then
              	Dim iFormIndex As Integer = 0
              	If TypeOf oNode.Tag Is GetType(Integer) Then iFormIndex = CInt(oNode.Tag)
              	Dim Children() As Form = Me.MdiChildren
              	Children(iFormIndex).Activate()
              End If
              C#
              Code:
              TreeNode oNode = null;
              if ((oNode != null) && (oNode.Tag != null)){
                Int32 iFormIndex = 0;
                if (typeof(oNode.Tag) == GetType(Int32)){
              	form[] Children = this.MdiChildren;
              	Children[iFormIndex].Activate();
                }
              }
              That should be akin to what you're looking for - it may need some tweaking to do exactly what you're after.

              Comment

              • fadah
                New Member
                • Mar 2008
                • 9

                #8
                Thanks for your replays.I will try those optionses out.

                Comment

                Working...