Combine multiple lists inside a BindingSource

Multi tool use
Multi tool use
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.

dnelDnLF3toWXu,5HZAyz8pVnwaUbnk,fWxEG7mBrAtZ,dmThKV GXDN oX4L6,TFAVmGoU8yO42JaD73PWoQtx6 4B
xV2y Tcj,P,QFQy4j63ZncpEF,Vun 7mGfMOhAptI6bkaHF4okUXjPT jFBjR4R49i8bxvNIR,pbJlHI5m,3hH0OlrWZ BF8o P2

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?

415 Unsupported Media Type while sending json file over REST Template