Hi Fenil
Check this example. Now please take its reference and correct your code.
Form1.Designer.cs
Namespaces
using System.Data;
Code
C#
public partial class Form1 : Form
{
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
this.BindDataGridView();
}
private void BindDataGridView()
{
dt.Columns.AddRange(new DataColumn[] {new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add("John Hammond", "United States");
dt.Rows.Add("Mudassar Khan", "India");
dt.Rows.Add("Suzanne Mathews", "France");
dt.Rows.Add("Robert Schidner", "Russia");
this.dataGridView1.DataSource = dt;
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("Cell is Updated : " + dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if ((treeView1.SelectedNode == null))
{
dataGridView1.DataSource = null;
return;
}
if ((treeView1.SelectedNode.Text == "Name"))
{
dataGridView1.DataSource = null;
return;
}
string sRef;
sRef = treeView1.SelectedNode.Text;
DataView dv = new DataView(dt);
dv.RowFilter = " Name = '" + sRef + "'";
dataGridView1.DataSource = dv;
}
}
Screenshot