使用组合框过滤texbox [英] Filtering a texbox with a combobox

查看:118
本文介绍了使用组合框过滤texbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我必须创建一个表单,它接受一个文件夹的内容,并在一个文本框中列出它(是的文本框不是一个列表框!)

Ok so I have to create a form that takes the contents of a folder and lists it in a textbox (yes a textbox not a list box!)

然后必须使用包含文件夹的所有扩展名的组合框过滤这个文本框(例如,如果我在组合框中选择.txt,文本框应该过滤显示所有文本文件!)

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!

顺便说一句,我使用c#,这是所有使用窗体窗体


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

推荐答案

在组合框的所选索引更改事件上,我将根据所选过滤器重写文本框中的信息。您可以使用System.IO.DirectoryInfo来筛选给定文件扩展名的目录。

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();

这篇关于使用组合框过滤texbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆