开发者

Filtering a texbox with a combobox

Ok so I have to create a form that takes the contents of a folder and lis开发者_JAVA技巧ts it in a textbox (yes a textbox not a list box!)

I then have to filter this textbox using a combobox which contains all the extensions of the folder (e.g. if i choose ".txt" in the combobox the textbox should filter to show all the text files only!)

I've managed to do everything bar getting the combobox to filter the textbox. I can't find any help anywhere online and am new to programming so please help!

By the way i'm using c# and this is all using windows forms


On the selected index changed event of the combo box, I'd rewrite the information in the text box based off of the filter selected. You can use System.IO.DirectoryInfo to filter your directory given a file extension.

StringBuilder fileNames = new StringBuilder();
DirectoryInfo dInfo = new DirectoryInfo(<string yourDirectory>);                                 
FileInfo[] fileInfo = dInfo.GetFiles("*" + <string yourChosenFileExtension>);
foreach (FileInfo file in fileInfo)
{  
   fileNames.Append(file.Name);
}
yourTextBox.Text = fileNames.ToString();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜