开发者

Creating items control binding source in C# from a listing of files in a specified path

I want to create a drop-down list of file names from a specified folder(path) the user can select from.

To get the list of file names itself, I was wanting to use the EnumerateFiles(String, String) method (I know how to get the list of file names)....but do not know how to take the list of files this method returns and create the values for the drop-down list.

The only way I've created a drop-down list in the project I am revising has been an enu开发者_运维技巧m--which of course had hard-coded values in it.


cmbFiles.DataSource=Directory.GetFiles(".");

Where cmbFiles is your combo box.


Assuming you don't (want to) use a datasource, you're looking for a way to populate a dropdown and set a value and a text property (so you have a unique identifier?). If so, there should be a ComboBoxItem.

comboBox1.Items.Add(new ComboBoxItem('unique_id', 'text_display'));

I don't remember if comboboxitem is built into the visual studios toolbox, I just know it exists... lol

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜