BindingSource Implementation in .net Win Forms
-
I have 2 .net forms, each with their own BindingSource which I set to go after the same DataTable. The table is filled early on with 35 rows. One of the BindingSources has a filter set when the form loads, which makes the result set 4 rows. When I go back to the first form, the row count has gone down to 4 - if I set that BindingSource filter to "", the count returns to 35. It looks as if the two binding sources are sharing stuff, where changing the filter on one affects the other. Any explanation for this? I am working around it but would like to understand the mechanism. Bob
-
I have 2 .net forms, each with their own BindingSource which I set to go after the same DataTable. The table is filled early on with 35 rows. One of the BindingSources has a filter set when the form loads, which makes the result set 4 rows. When I go back to the first form, the row count has gone down to 4 - if I set that BindingSource filter to "", the count returns to 35. It looks as if the two binding sources are sharing stuff, where changing the filter on one affects the other. Any explanation for this? I am working around it but would like to understand the mechanism. Bob
-
-
Thanks, if I read the docs right, it appears if I tie the binding sources to DataViews, not the DataTable, it might work as I intend and keep the filters separate...
Based on my own experience, I am just need to create public static DataTable datasource which is will be consumed by that 2 or more forms... Not just Datatable, but also collection, We can put it on main Program.cs, let's say it glbData.
public class Program{
public static DataTable glbData;
}usage :
DataTable dt = resultset[0]; //Result From Database
Program.glbData = dt;Regards Toha
-
Based on my own experience, I am just need to create public static DataTable datasource which is will be consumed by that 2 or more forms... Not just Datatable, but also collection, We can put it on main Program.cs, let's say it glbData.
public class Program{
public static DataTable glbData;
}usage :
DataTable dt = resultset[0]; //Result From Database
Program.glbData = dt;Regards Toha
And how does your solution solve the problem the poster had? Go ahead and try your solution with the problem the OP had.
This space for rent
-
And how does your solution solve the problem the poster had? Go ahead and try your solution with the problem the OP had.
This space for rent
I have test this and the first form not affected with changes from FormMahasiswa
private void FormMahasiswa_Load(object sender, EventArgs e)
{
Form1.glbData = new DataTable();
Form1.glbData.Columns.Add("Newww", typeof(int));
Form1.glbData.Columns.Add("Drug", typeof(string));
Form1.glbData.Columns.Add("Patient", typeof(string));
Form1.glbData.Columns.Add("Date", typeof(DateTime));// Here we add five DataRows. Form1.glbData.Rows.Add(25, "Sample Change", "Change ", DateTime.Now); Form1.glbData.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); Form1.glbData.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); Form1.glbData.Rows.Add(21, "Combivent", "Janet", DateTime.Now); Form1.glbData.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); dataGridView1.DataSource = Form1.glbData; }
Regards Toha