I have a problem with my combobox doing a search inside strings in elements. I want to narrow the list of participants. They are formatted in this way (unique identifier of the participant) - First name - last name.
When I leave all the settings “as is”, it will “allow” me to search in the first char in the string.
The DataSource is installed from the list, which is done from the loop through all the files in the folder.
The code I used is as follows (partial code)
private void searchForShooterComboBox_KeyUp(object sender, KeyEventArgs e)
{
}
private void searchForShooterComboBox_TextChanged(object sender, EventArgs e)
{
searchForShooterComboBox.DataSource = null;
searchForShooterComboBox.DataSource = fliterComboBox(searchForShooterComboBox, memberFileNames);
}
private List<string> fliterComboBox(ComboBox cobx, List<string> stringList)
{
List<string> returnList = new List<string>();
if (cobx.Text != ""){
try
{
foreach (string s in stringList)
{
if (s.Contains(cobx.Text))
{
returnList.Add(s);
}
}
}catch{
}
}
return returnList;
}
some code that I tried, apparently, was filtering the OK list, but after running the methods, it fills what appears to be the first element in the new list into a “text box”, so the user will not be able to continue to type ex.
ComboBox.Items.Add() ComboBox.Items.Remove() DataSource?
edit: comboBox form_load. , combobox:
searchForShooterComboBox.DropDownStyle = ComboBoxStyle.DropDown;
searchForShooterComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
searchForShooterComboBox.AutoCompleteSource = AutoCompleteSource.ListItems
, .