Combobox Items

  • Thread starter Thread starter Emil
  • Start date Start date
E

Emil

Is there a method for combobox's items collection to load
items from a file like in delphi. i mean a method like:
combobox1.items.loadfromfile(filepath)
 
Hello,

Emil said:
Is there a method for combobox's items collection to load
items from a file like in delphi. i mean a method like:
combobox1.items.loadfromfile(filepath)

AFAIK "no".

Regards,
Herfried K. Wagner
 
I havent tried it but could you serialise/deserialize the
Combo box items collection to an xml file?

guy
 
..NET doesn't have anything as nice as Delphi's TStrings class,
unfortunately. There is a StringCollection but it doesn't have a Text
property or LoadFrom/SaveTo File/Stream methods. I wound up writing my
own string collection to fill these gaps.

If you know your file is always going to have Windows-style line breaks,
then this isn't hard to implement yourself, as long as your text file is
reasonably small. Do something like this: read the entire file into a
string variable, then use String.Split() with "\r\n" to break it into
multiple lines and return a String[], then discard the last element in
the array (since it will always be an empty string if your file had a
trailing \r\n, as most text files do).

Let me know if you need sample code and I'll see if I can whip something up.
 
Back
Top