如何通过textchanged搜索组合框中的过滤器文件夹 [英] How can I search filter folders in combobox by textchanged
问题描述
我只想通过ComboBoxTextChanged搜索带有ComboBox的过滤器驱动器和文件夹
我可以将它与按钮一起使用Click但我只想在文本时动态在组合框中
当我尝试它时ComboBox文本全部选中,如果我想继续,我必须设置取消选择它。
如何在comboBox下搜索/过滤文件夹。
我尝试过:
I just want to Search Filter Drive and Folders with ComboBox by ComboBoxTextChanged
I can use it with button Click but I just want to do it dynamic when I text in comboBox
when I try it ComboBox Text Full Selected and if I want to continue I must set deselected it.
How cam I search/filter folders under comboBox.
What I have tried:
Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click
Try
ComboBox1.Items.Clear()
Expand(UCase(ComboBox1.Text))
Dim folders() As String = IO.Directory.GetDirectories(UCase(ComboBox1.Text)) '("C:\7143")
For Each folder As String In folders
ComboBox1.Items.Add(folder)
ComboBox1.DroppedDown = True
Next
Catch ex As Exception
End Try
End Sub
推荐答案
创建一个从ComboBox派生的控件,并覆盖OnTextChanged方法:
Create a control derived from ComboBox, and override the OnTextChanged method:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace OneOffJobs
Public Class MyComboBox
Inherits ComboBox
Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
MyBase.OnTextChanged(e)
Console.WriteLine(Text)
End Sub
End Class
End Namespace
而不是Console.WriteLine,哟你可以随心所欲。
然后在yoru表单上使用它而不是ComboBox控件。
Instead of Console.WriteLine, you can do whatever you want.
Then use that instead of a ComboBox control on yoru form.
这篇关于如何通过textchanged搜索组合框中的过滤器文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!