Combine multiple lists inside a BindingSource

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Combine multiple lists inside a BindingSource



I'm using a BindingSource to gather up some DataGridViews on multiple database calls.


BindingSource


DataGridView



What I want to do is combined all the DataGridViews 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.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS