I am trying to bind the ConnectionStringsSettingsCollection from my app.config file to a ListBox in my WinForms app. For some reason, I can’t seem to do it by the following method:
lstMyListBox.DataSource = GetConnectionStrings()
lstMyListBox.DisplayMember = "Name"
I am able to do it by iterating over the collection and adding each ConnectionStringSetting to lstMyListBox.Items:
For Each settings As ConnectionStringSettings In GetConnectionStrings()
lstMyListBox.Items.Add(settings)
Next
lstMyListBox.DisplayMember = "Name"
Which works as far as modifying the individual items that are already in the collection, but I would like it if I remove something from the ListBox that it is removed from the underlying collection. Is there something I can do different that will allow me to bind the ListBox directly to the ConnectionStringSettingsCollection?
ConnectionStringsSettingsCollectiondoesn’t implementIListorIListSource, so it can’t be used as aDataSource. Instead you can bind a list ofConnectionStringSettings:However the
DisplayMemberdoesn’t seem to be taken into account, at least not for all items… but it works fine if you use “ConnectionString” as theDisplayMember. Not sure why…