giannis said:
How can i do this with a combo box ?
giannis,
Here's an example.
On the combobox:
Set AutoCompleteMode to SuggestAppend.
Set AutoCompleteSource to CustomSource.
'this loads my combobox and binds it
Private Sub LoadManagerComboBox()
If MgrList IsNot Nothing AndAlso MgrList.Count > 0 Then
MgrList = Nothing 'blank out the table
End If
'create the list that is going to be bound to the combobox
'this could just as easily be a datatable
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
'this builds the autocomplete strings
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
Good luck,
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.