Combine multiple lists inside a BindingSource
Combine multiple lists inside a BindingSource
I'm using a BindingSource
to gather up some DataGridView
s on multiple database calls.
BindingSource
DataGridView
What I want to do is combined all the DataGridView
s in the .List
property of the BindingSource
into one so I can use DataGridView.DataSource = BindingSource
.
DataGridView
.List
BindingSource
DataGridView.DataSource = BindingSource
I've tried the following, but it only binds the collection itself and not the .List
properties.
.List
BindingSource _bindingSource = new BindingSource();
...
...
while(<doing database calls>) {
// Populate _DataGridView with some a DB Call
_bindingSource.Add(_DataGridView); // Add _DataGridView to the _bindingSource
}
DataGrid.Datasource = _bindingSource;
What I want is something like this
// Populate _bindingSource with the .List property/or all the items within _bindingSource
DataGrid.Datasource = _bindingSource[0] + _bindingSource[1] + ..
1 Answer
1
DataSource
is object
.
DataSource
object
So you will need to know more about the actual DS you are using; then you can (maybe using a suitable Cast<>
) Concat
(or Union
) the various enumerations.
Cast<>
Concat
Union
Let's look at a simple example using DataGridViews
that are bound to DataTables
:
DataGridViews
DataTables
var twoDataSources = ((DataTable)dataGridView1.DataSource).Select()
.Concat(((DataTable)dataGridView2.DataSource).Select());
var twoDataSources = ((DataTable)dataGridView1.DataSource).Select()
.Union(((DataTable)dataGridView2.DataSource).Select());
The first example contains each row in each table; the seconds contains all unique rows.
If you need more help please add the actual code that creates the datasources. (Of course they would have to be field-compatible..)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.