0

In my form I set a listbox and combobox to the same datasource like this

    public DetailsForm()
    {
        InitializeComponent();

        this.categories_comboBox.DataSource = TextSelectionSettings.Default.categories;
        this.categories_listBox.DataSource = TextSelectionSettings.Default.categories;
    }

The items I have listed in the collection show up in the listbox and combobox, but when I click an item in the listbox, it changes the selected item in the combobox, and vice versa. This is not what I expected, because I have no events defined yet for either control.

Is there a way to decouple the two?

EDIT: categories is of type

System.Collections.Specialized.StringCollection

and the TextSelectionSettings are ApplicationSettings

erotavlas
  • 4,274
  • 4
  • 45
  • 104
  • what's the data type of categories? – Ctznkane525 Apr 09 '18 at 18:22
  • @Ctznkane525 StringCollection – erotavlas Apr 09 '18 at 18:25
  • 2
    You have bound both to the same datasource, so what do you expect?? You may add one or two `.ToList()` to create copies if you want to have them independent or insert a BindingSource. – TaW Apr 09 '18 at 18:30
  • @TaW Why should viewing the datasource have an effect on what is selected? I'm not changing any data. – erotavlas Apr 09 '18 at 18:31
  • But as you have not added a layer with a 'cursor' both share the 'cursor'. A datasource is more than just the data. - You change the 'cursor' (aka rowpointer)... – TaW Apr 09 '18 at 18:38
  • @TaW makes no sense.....when I do the same thing in WPF application the two controls are not coupled in this way, changing one does not affect the other. I just tried it setting ItemSource for listbox and combobox to the exact same StringCollection in the application settings. This is the expected behavior. – erotavlas Apr 09 '18 at 18:41
  • So? a) What's got WPF got to do with it? b) It may come handy sometimes. c) Does it work now? – TaW Apr 09 '18 at 18:42
  • @TaW an example of how it should work. – erotavlas Apr 09 '18 at 18:44
  • It can work either way, your pick. Knowing the rules is always necessary. – TaW Apr 09 '18 at 18:47
  • 1
    @TaW agreed, thanks for pointing out that other solution, setting the binding sources independently solved my problem. – erotavlas Apr 09 '18 at 18:48

0 Answers0