Link to home
Start Free TrialLog in
Avatar of yuvarajr
yuvarajr

asked on

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

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..
Avatar of glsac
glsac
Flag of United States of America image

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;
            }

      }
}
ASKER CERTIFIED SOLUTION
Avatar of monosodiumg
monosodiumg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yuvarajr
yuvarajr

ASKER

Thanks a lot guys..
Your very welcome my friend.

Aeros