Take a look at Scott Mitchell's article on grouping by category at
http://datawebcontrols.com/faqs/DataLists/GroupingByCategory.shtml

Bob Filipiak
A question not asked
  is a lost opportunity to learn.
----- Original Message ----- 
From: "Arindam" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 27, 2004 3:15 AM
Subject: [AspNetAnyQuestionIsOk] how to make a treeView (populated from
database).



Hello
Friend,
Here I am trying to make a treeView (populated from database).
Hierarchy is
Country >> State >> City
ParentNode >> mainChildNode >> subChildNode

Problem Is:
Same Country is getting repeated. Which I don't want.

Secondly in while loop how can I relate the child node with parent node

Request:
Please have a look at the code .

Many many thaks in advance for good suggestion & idea with a sample code.

***************Code Start Here**********************


private void makeTreeview()
  {
   try
   {
string strSql = "SELECT oCountry,oState,oCity FROM regDtls order by oName";
 myconnection conClass = new myconnection();
 conClass.openConnection();
 SqlCommand sqlCom=new SqlCommand(strSql,conClass.mysqlconn);
 SqlDataReader
myReader=sqlCom.ExecuteReader(CommandBehavior.CloseConnection);

    int a=0;
    string preCountry="";
    while (myReader.Read())
    {
     for (int i=0;i<=a ;i++)
     {
  if ((preCountry.Trim()!=(myReader.GetValue(0).ToString().Trim())))
      {
 treeView1.Nodes.Add(new TreeNode(myReader.GetValue(0).ToString()));//add
country

      for (int j=0;j<=2;j++)
      {
treeView1.Nodes[i].Nodes.Add(new
TreeNode(myReader.GetValue(1).ToString()));//add State

       for (int k=0;k<=3;k++)
       {
treeView1.Nodes[i].Nodes[j].Nodes.Add(new
TreeNode(myReader.GetValue(2).ToString()));//add City
       }
      }
     }//if end here
     }
preCountry=myReader.GetValue(0).ToString().Trim() ;
 //  MessageBox.Show(preCountry);
     a=a+1;
    }

 //   MessageBox.Show(a.ToString() );
  myReader.Close ();
   }

   catch (Exception ex)
   {
    MessageBox.Show(ex.Source);
    MessageBox.Show(ex.Message);
   }
   treeView1.BeginUpdate();

   // Reset the cursor to the default for all controls.
   Cursor.Current = Cursors.Default;

   // Begin repainting the TreeView.
   treeView1.EndUpdate();

  }



Regards

Arindam



Yahoo! India Matrimony: Find your partner online.

[Non-text portions of this message have been removed]





Yahoo! Groups Links








------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 

Reply via email to