select tree node to display the related gridview
i have the tree node in windows form application ,while i am click the tree node to display the related gridview in C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 14, 2012, 12:31 PM
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Treeview_Node__Related_data
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
treeView1.Nodes.Add("Please select any table");
treeView1.Nodes.Add("student");
treeView1.Nodes.Add("employee");
treeView1.Nodes.Add("product");
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
if (treeView1.SelectedNode.Text == "Please select any table")
{
}
else if (treeView1.SelectedNode.Text == "student")
{
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "student");
dataGridView1.DataMember = "student";
dataGridView1.DataSource = ds;
con.Close();
dataGridView1.Visible = true;
dataGridView2.Visible = false;
dataGridView3.Visible = false;
}
else if (treeView1.SelectedNode.Text == "employee")
{
con.Open();
str = "select * from employee";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "employee");
dataGridView2.DataMember = "employee";
dataGridView2.DataSource = ds;
con.Close();
dataGridView1.Visible = false;
dataGridView2.Visible = true;
dataGridView3.Visible = false;
}
else if (treeView1.SelectedNode.Text == "product")
{
con.Open();
str = "select * from product";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "product");
dataGridView3.DataMember = "product";
dataGridView3.DataSource = ds;
con.Close();
dataGridView1.Visible = false;
dataGridView2.Visible = false;
dataGridView3.Visible = true;
}
}
}
}
Thanks
If this post helps you mark it as answer