|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to: Different filters for two binding sources with the same data sourceis it possible to set different filters for two binding sources with the same data source? If so, how? I tried to use this code: BindingSource bindingSource1 = new BindingSource(); BindingSource bindingSource2 = new BindingSource(); bindingSource1.DataSource = myDataSet.Tables["tblname"]; dataGridView1.DataSource = bindingSource1; dataGridView1.Columns["colname1"].DataPropertyName = "colname1db"; // etc. for every column from the DGV1 bindingSource2.DataSource = myDataSet.Tables["tblname"]; // i.e. the same source as for the first bindingSource1 bindingSource2.Filter = "filtercol = 'value'"; // records in DGV1 are now filtered too! dataGridView2.DataSource = bindingSource2; dataGridView2.Columns["colname1"].DataPropertyName = "colname1db"; // etc. for every column from the DGV2 The thing I do not understand is why is the filter applied also to the records shown in DGV1, while the filter is set for the binding source assigned to DGV2... TIA With regards nvx Hi there,
When you bind to a datatable you actually bind its DefaultView which is a DataView instance. Thus, create a new DataView for that table and bind it to the other BindingSource and you'll have two different views which will have different filters. -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "nvx" <nvx2***@hotmail.com> wrote in message news:1174301295.585493.246180@l77g2000hsb.googlegroups.com... > Hi, > is it possible to set different filters for two binding sources with > the same data source? If so, how? I tried to use this code: > > BindingSource bindingSource1 = new BindingSource(); > BindingSource bindingSource2 = new BindingSource(); > > bindingSource1.DataSource = myDataSet.Tables["tblname"]; > dataGridView1.DataSource = bindingSource1; > dataGridView1.Columns["colname1"].DataPropertyName = "colname1db"; > // etc. for every column from the DGV1 > > bindingSource2.DataSource = myDataSet.Tables["tblname"]; // i.e. the > same source as for the first bindingSource1 > bindingSource2.Filter = "filtercol = 'value'"; // records in DGV1 are > now filtered too! > dataGridView2.DataSource = bindingSource2; > dataGridView2.Columns["colname1"].DataPropertyName = "colname1db"; > // etc. for every column from the DGV2 > > The thing I do not understand is why is the filter applied also to the > records shown in DGV1, while the filter is set for the binding source > assigned to DGV2... > > TIA > > With regards > nvx > Hello Miha,
thanks a lot for your advice. It works great... :) Have a nice day... With regards nvx Miha Markic [MVP C#] napsal: Show quote > Hi there, > > When you bind to a datatable you actually bind its DefaultView which is a > DataView instance. > Thus, create a new DataView for that table and bind it to the other > BindingSource and you'll have two different views which will have different > filters. > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > "nvx" <nvx2***@hotmail.com> wrote in message > news:1174301295.585493.246180@l77g2000hsb.googlegroups.com... > > Hi, > > is it possible to set different filters for two binding sources with > > the same data source? If so, how? I tried to use this code: > > > > BindingSource bindingSource1 = new BindingSource(); > > BindingSource bindingSource2 = new BindingSource(); > > > > bindingSource1.DataSource = myDataSet.Tables["tblname"]; > > dataGridView1.DataSource = bindingSource1; > > dataGridView1.Columns["colname1"].DataPropertyName = "colname1db"; > > // etc. for every column from the DGV1 > > > > bindingSource2.DataSource = myDataSet.Tables["tblname"]; // i.e. the > > same source as for the first bindingSource1 > > bindingSource2.Filter = "filtercol = 'value'"; // records in DGV1 are > > now filtered too! > > dataGridView2.DataSource = bindingSource2; > > dataGridView2.Columns["colname1"].DataPropertyName = "colname1db"; > > // etc. for every column from the DGV2 > > > > The thing I do not understand is why is the filter applied also to the > > records shown in DGV1, while the filter is set for the binding source > > assigned to DGV2... > > > > TIA > > > > With regards > > nvx > > |
|||||||||||||||||||||||