Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 36
@Html.EditorFor displays mm/dd/yyyy rather than date 2 33
Execute Stored Procedure for a set of values 5 42
Error in JQuery 5 35
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

930 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

13 Experts available now in Live!

Get 1:1 Help Now