Nabil code create and populate the tables itself. If it does not coincide with yours - do not blame me.
Here is a fully working example. Data binding is used. And you only need a couple of lines of code in the event to change the filter. As a result, the contents of the third grid depends on the selected lines in the first two.
using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { //InitializeComponent(); Size = new Size(500, 600); var dtData = new DataTable("Data"); dtData.Columns.Add("id", typeof(int)); dtData.Columns.Add("value", typeof(string)); dtData.Rows.Add(1, "data1"); dtData.Rows.Add(2, "data2"); var dtTypeHistory = new DataTable("TypeHistory"); dtTypeHistory.Columns.Add("id", typeof(int)); dtTypeHistory.Columns.Add("value", typeof(string)); dtTypeHistory.Rows.Add(11, "type1"); dtTypeHistory.Rows.Add(12, "type2"); var dtHistory = new DataTable("History"); dtHistory.Columns.Add("id", typeof(int)); dtHistory.Columns.Add("FK_Data", typeof(int)); dtHistory.Columns.Add("FK_TypeHistory", typeof(int)); dtHistory.Rows.Add(101, 1, 11); dtHistory.Rows.Add(102, 1, 12); dtHistory.Rows.Add(103, 2, 11); dtHistory.Rows.Add(104, 2, 12); var ds = new DataSet(); ds.Tables.Add(dtData); ds.Tables.Add(dtTypeHistory); ds.Tables.Add(dtHistory); ds.Relations.Add("FK_History_ToData", dtData.Columns["id"], dtHistory.Columns["FK_Data"]); ds.Relations.Add("FK_History_ToTypeHistory", dtTypeHistory.Columns["id"], dtHistory.Columns["FK_TypeHistory"]); var flp = new FlowLayoutPanel { Parent = this, Dock = DockStyle.Fill }; var dgvData = new DataGridView { Parent = flp, Width = 400 }; var dgvTypeHistory = new DataGridView { Parent = flp, Width = 400 }; var dgvHistory = new DataGridView { Parent = flp, Width = 400 }; var bsData = new BindingSource(); bsData.DataSource = ds; bsData.DataMember = "Data"; var bsTypeHistory = new BindingSource(); bsTypeHistory.DataSource = ds; bsTypeHistory.DataMember = "TypeHistory"; var bsHistory = new BindingSource(); bsHistory.DataSource = bsData; bsHistory.DataMember = "FK_History_ToData"; dgvTypeHistory.SelectionChanged += (s, e) => { string id = dgvTypeHistory.CurrentRow.Cells["id"].Value.ToString(); bsHistory.Filter = "FK_TypeHistory = " + id; }; dgvData.DataSource = bsData; dgvTypeHistory.DataSource = bsTypeHistory; dgvHistory.DataSource = bsHistory; } } }
In your video, some kind of combo box appears. I did not delve into the nuances. But it’s not hard to add a BindingSource filter change on a combo box change event.