Problem with two controls sharing the same data source

I am creating a winforms application, I have two comboboxes that have the same data source, the data source is DataTable. Now, when I select a value in one comboBox, the value of another comboBox also changes. Is there a way to change it without affecting others?

+3
source share
2 answers

In this type of scenario, you can create two different sources of binding, bound to each of your lists. If you set a property DataSourcefor each of the binding data sources DataTable, then your combined fields will work independently, and the same data will be displayed.

:

// Initialization of the binding sources(assuming dataTable is a populated DataTable)
bindingSource.DataSource = dataTable;
bindingSource2.DataSource = dataTable;
+1

WinForms , combobox () .

, , combobox DataSource.

- (BindingSource).

, , BindingList. , BindingList - ​​ :

[The] BindingList WRAPPER . , . ( , , Reflector). - http://www.nichesoftware.co.nz/blog/200809/databinding-lists

:

editDebitAccount.DataSource = accountsList;
editCreditAccount.DataSource = accountsList;

:

editDebitAccount.DataSource = new BindingList(accountsList);
editCreditAccount.DataSource = new BindingList(accountsList);
+1

Source: https://habr.com/ru/post/1721441/


All Articles