By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,979 Members | 1,349 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,979 IT Pros & Developers. It's quick & easy.

Auto Complete Folder Combobox

P: n/a
Does anyone have some sample code for building a combobox that will
automatically list the remaining folders while you type? I'm looking for
functionality similar to the "Look in:" combobox in the Search Companion
panel in Windows Explorer. If you type "C:\" it will open the drop down and
fill it in with all of the directories on C:\. Then as you type letters it
will re-fill the drop down with only the folders that match your typing.

Thanks,
John
Jan 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Since nobody has answered this, I'm going to post a response.
This example is in VB2005 (hey, it's better than nothing).
On the combobox:
Set AutoCompleteMode to SuggestAppend.
Set AutoCompleteSource to CustomSource.

Private Sub LoadManagerComboBox()
If MgrList IsNot Nothing AndAlso MgrList.Count 0 Then
MgrList = Nothing 'blank out the table
End If
MgrList = PTBO.ManagerList.Create("ManagerName")
'bind the combo box to the list
ManagerComboBox.DataSource = MgrList
ManagerComboBox.DisplayMember = "FullName"
ManagerComboBox.ValueMember = "UserID"
ManagerComboBox.SelectedIndex = -1
Call BuildAutoCompleteStrings()
End Sub

Private Sub BuildAutoCompleteStrings()
'If the manager list doesn't have any entries, return.
If MgrList.Count <= 0 OrElse ManagerComboBox.Items.Count <= 0 Then
Return
End If
' Clear what is in there now
ManagerComboBox.AutoCompleteCustomSource.Clear()
'Set the column name.
Dim filterField As String = "FullName"
' Build the list of filter values.
Dim filterVals As AutoCompleteStringCollection = _
New AutoCompleteStringCollection()
For Each dataItem As Object In MgrList
Dim props As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(dataItem)
Dim propDesc As PropertyDescriptor = _
props.Find(filterField, True)
Dim fieldVal As String = _
propDesc.GetValue(dataItem).ToString()
filterVals.Add(fieldVal)
Next
' Set the list on the collection.
ManagerComboBox.AutoCompleteCustomSource = filterVals
End Sub

Robin S.
------------------------------------------------
"John" <go*******@hotmail.comwrote in message
news:eB**************@TK2MSFTNGP02.phx.gbl...
Does anyone have some sample code for building a combobox that will
automatically list the remaining folders while you type? I'm looking
for functionality similar to the "Look in:" combobox in the Search
Companion panel in Windows Explorer. If you type "C:\" it will open
the drop down and fill it in with all of the directories on C:\. Then
as you type letters it will re-fill the drop down with only the
folders that match your typing.

Thanks,
John

Jan 27 '07 #2

P: n/a
Thanks Robin. I'll check this out tonight. I had sort of given up hope for
an example. I'll post this in C# once I get it working.

John
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:S5******************************@comcast.com. ..
Since nobody has answered this, I'm going to post a response.
This example is in VB2005 (hey, it's better than nothing).
On the combobox:
Set AutoCompleteMode to SuggestAppend.
Set AutoCompleteSource to CustomSource.

Private Sub LoadManagerComboBox()
If MgrList IsNot Nothing AndAlso MgrList.Count 0 Then
MgrList = Nothing 'blank out the table
End If
MgrList = PTBO.ManagerList.Create("ManagerName")
'bind the combo box to the list
ManagerComboBox.DataSource = MgrList
ManagerComboBox.DisplayMember = "FullName"
ManagerComboBox.ValueMember = "UserID"
ManagerComboBox.SelectedIndex = -1
Call BuildAutoCompleteStrings()
End Sub

Private Sub BuildAutoCompleteStrings()
'If the manager list doesn't have any entries, return.
If MgrList.Count <= 0 OrElse ManagerComboBox.Items.Count <= 0 Then
Return
End If
' Clear what is in there now
ManagerComboBox.AutoCompleteCustomSource.Clear()
'Set the column name.
Dim filterField As String = "FullName"
' Build the list of filter values.
Dim filterVals As AutoCompleteStringCollection = _
New AutoCompleteStringCollection()
For Each dataItem As Object In MgrList
Dim props As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(dataItem)
Dim propDesc As PropertyDescriptor = _
props.Find(filterField, True)
Dim fieldVal As String = _
propDesc.GetValue(dataItem).ToString()
filterVals.Add(fieldVal)
Next
' Set the list on the collection.
ManagerComboBox.AutoCompleteCustomSource = filterVals
End Sub

Robin S.
------------------------------------------------
"John" <go*******@hotmail.comwrote in message
news:eB**************@TK2MSFTNGP02.phx.gbl...
>Does anyone have some sample code for building a combobox that will
automatically list the remaining folders while you type? I'm looking for
functionality similar to the "Look in:" combobox in the Search Companion
panel in Windows Explorer. If you type "C:\" it will open the drop down
and fill it in with all of the directories on C:\. Then as you type
letters it will re-fill the drop down with only the folders that match
your typing.

Thanks,
John


Feb 6 '07 #3

P: n/a
You're welcome.

The irony is, I first saw it in Brian Noyes' Data Binding book, where all
the examples are in C#. It's a great book, if you're doing much data
binding, and it's responsible for the C# I *do* know, because I had to
figure it out to read the book. (I'm sure it made me a better person).

Good luck.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"John" <go*******@hotmail.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
Thanks Robin. I'll check this out tonight. I had sort of given up hope
for an example. I'll post this in C# once I get it working.

John
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:S5******************************@comcast.com. ..
>Since nobody has answered this, I'm going to post a response.
This example is in VB2005 (hey, it's better than nothing).
On the combobox:
Set AutoCompleteMode to SuggestAppend.
Set AutoCompleteSource to CustomSource.

Private Sub LoadManagerComboBox()
If MgrList IsNot Nothing AndAlso MgrList.Count 0 Then
MgrList = Nothing 'blank out the table
End If
MgrList = PTBO.ManagerList.Create("ManagerName")
'bind the combo box to the list
ManagerComboBox.DataSource = MgrList
ManagerComboBox.DisplayMember = "FullName"
ManagerComboBox.ValueMember = "UserID"
ManagerComboBox.SelectedIndex = -1
Call BuildAutoCompleteStrings()
End Sub

Private Sub BuildAutoCompleteStrings()
'If the manager list doesn't have any entries, return.
If MgrList.Count <= 0 OrElse ManagerComboBox.Items.Count <= 0 Then
Return
End If
' Clear what is in there now
ManagerComboBox.AutoCompleteCustomSource.Clear()
'Set the column name.
Dim filterField As String = "FullName"
' Build the list of filter values.
Dim filterVals As AutoCompleteStringCollection = _
New AutoCompleteStringCollection()
For Each dataItem As Object In MgrList
Dim props As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(dataItem)
Dim propDesc As PropertyDescriptor = _
props.Find(filterField, True)
Dim fieldVal As String = _
propDesc.GetValue(dataItem).ToString()
filterVals.Add(fieldVal)
Next
' Set the list on the collection.
ManagerComboBox.AutoCompleteCustomSource = filterVals
End Sub

Robin S.
------------------------------------------------
"John" <go*******@hotmail.comwrote in message
news:eB**************@TK2MSFTNGP02.phx.gbl...
>>Does anyone have some sample code for building a combobox that will
automatically list the remaining folders while you type? I'm looking
for functionality similar to the "Look in:" combobox in the Search
Companion panel in Windows Explorer. If you type "C:\" it will open the
drop down and fill it in with all of the directories on C:\. Then as
you type letters it will re-fill the drop down with only the folders
that match your typing.

Thanks,
John



Feb 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.