Solved

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

Posted on 2004-09-27
5
742 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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 …

749 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