Solved

IE webcontrols treeview - how to make a node selected thro' code?

Posted on 2004-09-27
5
737 Views
Last Modified: 2008-02-20
Hi Experts,
I'm using IE webcontrols treeview. I need to have a particular node in the tree hierarchy selected..Is that possible? I see a property called "expanded" which shows a specific node expanded but i dont see any property like "selected"..

Could someone pls help?.. Or is there any other treeview better than this?

Thanks in advance..
0
Comment
Question by:yuvarajr
5 Comments
 
LVL 9

Expert Comment

by:glsac
ID: 12167479
Some code I did....gets selected from database, then selects it in tree:

      public class MeetingGicsDlg : MeetingDlgBase
      {
            protected Microsoft.Web.UI.WebControls.TreeView GicsTreeView;
            protected System.Web.UI.HtmlControls.HtmlInputHidden gics;
            protected System.Web.UI.WebControls.Button Submit;

            private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!Page.IsPostBack)
                  {
                        this.Initialize();
                        BindGicNodes();
                  }
            }

            /// <summary>
            /// Adds all nodes to a parent node in the Gic tree based on the
            /// index of the node.
            /// </summary>
            protected void BindGicNodes()
            {
                  MeetingGicData dsSectors = GICSystem.GetGicsSectors(this.MeetingID);

                  if (dsSectors.Tables[0].Rows.Count > 0)
                  {
                        for (int i = 0; i < dsSectors.MEETING_GIC.Rows.Count; i++)
                        {
                              TreeNode nodeSector = new TreeNode();
                              nodeSector.ID = dsSectors.MEETING_GIC[i].GIC_ID.ToString();
                              nodeSector.Text = dsSectors.MEETING_GIC[i].GIC_DESCRIPTION;
                              nodeSector.CheckBox = true;
                              nodeSector.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Auto;
                              nodeSector.Checked = dsSectors.MEETING_GIC[i].MEETING_ID != 0;
                              GicsTreeView.Nodes.Add(nodeSector);

                              MeetingGicData dsGroups = GICSystem.GetByGicParentID(dsSectors.MEETING_GIC[i].GIC_ID, this.MeetingID);
                              if (dsGroups.Tables[0].Rows.Count > 0)
                              {
                                    for (int j = 0; j < dsGroups.Tables[0].Rows.Count; j++)
                                    {
                                          TreeNode nodeGroup = new TreeNode();
                                          nodeGroup.ID = dsGroups.MEETING_GIC[j].GIC_ID.ToString();
                                          nodeGroup.Text = dsGroups.MEETING_GIC[j].GIC_DESCRIPTION;
                                          nodeGroup.CheckBox = true;
                                          nodeGroup.Checked = dsGroups.MEETING_GIC[j].MEETING_ID != 0;
                                          if(nodeGroup.Checked)
                                          {
                                                nodeSector.Expanded = true;
                                          }
                                          nodeGroup.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Auto;
                                          nodeSector.Nodes.Add(nodeGroup);

                                          MeetingGicData dsInd = GICSystem.GetByGicParentID(dsGroups.MEETING_GIC[j].GIC_ID, this.MeetingID);
                                          if (dsInd.Tables[0].Rows.Count > 0)
                                          {
                                                for (int k = 0; k < dsInd.Tables[0].Rows.Count; k++)
                                                {
                                                      TreeNode nodeInd = new TreeNode();
                                                      nodeInd.ID = dsInd.MEETING_GIC[k].GIC_ID.ToString();
                                                      nodeInd.Text = dsInd.MEETING_GIC[k].GIC_DESCRIPTION;
                                                      nodeInd.CheckBox = true;
                                                      nodeInd.Checked = dsInd.MEETING_GIC[k].MEETING_ID != 0;
                                                      if(nodeInd.Checked)
                                                      {
                                                            nodeGroup.Expanded = true;
                                                            nodeSector.Expanded = true;
                                                      }

                                                      nodeInd.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Auto;
                                                      nodeGroup.Nodes.Add(nodeInd);

                                                      MeetingGicData dsSubInd = GICSystem.GetByGicParentID(dsInd.MEETING_GIC[k].GIC_ID, this.MeetingID);
                                                      if (dsSubInd.Tables[0].Rows.Count > 0)
                                                      {
                                                            for (int l = 0; l < dsSubInd.Tables[0].Rows.Count; l++)
                                                            {
                                                                  TreeNode nodeSubInd = new TreeNode();
                                                                  nodeSubInd.ID = dsSubInd.MEETING_GIC[l].GIC_ID.ToString();
                                                                  nodeSubInd.Text = dsSubInd.MEETING_GIC[l].GIC_DESCRIPTION;
                                                                  nodeSubInd.CheckBox = true;
                                                                  nodeSubInd.Checked = dsSubInd.MEETING_GIC[l].MEETING_ID != 0;
                                                                  if(nodeSubInd.Checked)
                                                                  {
                                                                        nodeInd.Expanded = true;
                                                                        nodeGroup.Expanded = true;
                                                                        nodeSector.Expanded = true;
                                                                  }
                                                                  nodeSubInd.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Auto;
                                                                  nodeInd.Nodes.Add(nodeSubInd);
                                                            }
                                                      }
                                                }
                                          }
                                    }
                              }
                        }
                  }
            }


            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.Submit.Click += new System.EventHandler(this.Submit_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private int AddSelectedGics(TreeNodeCollection nodes)
            {
                  int nChecked = 0;
                  foreach (TreeNode tn in nodes)
                  {
                        int nChildChecked = 0;
                        if (tn.Nodes.Count > 0)
                        {
                              nChildChecked = AddSelectedGics(tn.Nodes);
                        }
                        if(tn.Checked)
                        {
                              if(nChildChecked == 0)
                              {
                                    MeetingSystem.AddMeetingGic(this.MeetingID, Convert.ToInt32(tn.ID));
                              }
                              nChildChecked++;
                              nChecked += nChildChecked;
                        }
                  }

                  return nChecked;
            }

      }
}
0
 
LVL 12

Accepted Solution

by:
monosodiumg earned 200 total points
ID: 12168445
The property is selectedIndex. It takes a string which is the path from root to the node. E.g.
MyTreeView.SelectedNodeIndex = "0.2"
will select the third child (2) of the first child (0) of the root.
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 50 total points
ID: 12168624
0
 

Author Comment

by:yuvarajr
ID: 12171578
Thanks a lot guys..
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12171585
Your very welcome my friend.

Aeros
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now