Load .dat Files into a ComboBox

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
Is there a way to load what is saved in .dat files in a specified directory?

I have it so the user has a log in form and when they enter a user name and click log in it saves that user name in a .dat file and the .dat file is also named by the user name they entered.

So I need a way for the ComboBox to see all the .dat files in a certain directory and then take the text in each one and put it in the ComboBox
 
You can use the StreamReader to read the dat file in with .ReadToEnd , then use .Replace to replace the Environment.NewLine with some character, like "ÿ. Then, use .Split to split the whole string at this "ÿ", effectively splitting the string at the newline. With this new array, you can use the .Items.AddRange(...) of either the combobox or the listbox to add the items.

control.Items.AddRange(streamreader.ReadToEnd().Replace(...).Split(...))
:)
 
Back
Top