.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How To Add Items In Treeview?

Posted By:Ghanashyam Nayak       Posted Date: September 12, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

At Runtime It Will Add Items Which Selected From The Combobox in Treeview At Runtime...
 


This Article Is For Add New Items In Treeview From The Database At Runtime...


I Have Used One Combobox, One Button & One Treeview.

From The Combobox User Will Select That Which Field Data Enter In The Tree view at Run time...

After Selecting The Combo box Item It Will Add That Field Data In The Treeview...



Table Which I Have Used As Below :


=====================================
---------------------------------------------------------------------
Student 
---------------------------------------------------------------------
=====================================
StudentId Name Address
=====================================
1 ABC ABC
2 XYZ XYZ
3 DEF DEF
4 PQR PQR
5 IJK IJK
=====================================


01.private void button1_Click(object sender, EventArgs e)
02.{
03.    OleDbConnection Conn = newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<>");
04.    try
05.    {
06.        Conn.Open();
07.        OleDbDataReader dr;
08.        string str = "SELECT '" + FieldComboBox.SelectedItem.ToString() +"' FROM Student";
09.        OleDbCommand cmd = new OleDbCommand(str, Conn);
10.        dr = cmd.ExecuteReader();
11.        while (dr.Read())
12.        {
13.            //Here "Node[0]" Means It Will Add Nodes In Root Node...
14.            MyAgeTreeView.Nodes[0].Nodes.Add(dr.GetValue(0).ToString());
15.        }
16.        Conn.Close();
17.    }
18.    catch (Exception ex)
19.    {
20.        MessageBox.Show(ex.ToString());
21.    }
22.}

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend