Solved

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

Posted on 2004-09-27
5
739 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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