1

Is it possible to convert a StringCollection variable to a BindingList, and then back? I am trying to bind a StringCollection to a DataGridView, and I am struggling to make it work.

I want to do the same thing with a StringDictionary.

Do I need to create some sort of wrapper classes to accomplish this...as described in this question.

Thanks for any advice you can give.

Community
  • 1
  • 1
rogdawg
  • 687
  • 3
  • 11
  • 33

2 Answers2

0

Will this work for you ?

        StringCollection sc = new StringCollection();

        BindingList<String> bl = new BindingList<String>((from String str in sc select str).ToList());
bang
  • 4,982
  • 1
  • 24
  • 28
  • This works for converting the datatype but, when I bind the BindingList to a DataGridView, it does not work correctly. I went back to the article I linked to in my original question and worked through it carefully. I was finally able to work through my errors and get that solution to work. It is an elegant solution, once I figured out how use a custom class as an Application.Settings data type, instead of using the StringCollection. That is the root issue of all of this. Thanks very much for your answer. I will keep syntax you demonstrate, and use it in other areas. – rogdawg Feb 15 '12 at 16:48
0

The answer provided for this question solves the issue I was addressing here. Once I carefully worked through the solution given, and corrected my own errors in implementing it, I was able to get it working.

It is an elegant solution.

Community
  • 1
  • 1
rogdawg
  • 687
  • 3
  • 11
  • 33