I'm trying to implement an auto-complete text box on Windows Forms using data from a PostgreSQL database. Let me try to explain my problem:
In the database, I have a table that has firstName and lastName fields separately.
In my Windows Forms application, I want to provide the opportunity to search using either firstName or lastName and provide the AutoComplete options from there.
So for example, if I have an entry on the table with firstName "Goat" and lastName "McGoats", I want to be able to get "Goat McGoats" (firstName {space} lastName) as a suggestion in my Windows Form text box whether I type in "G" or "M" - the start of either first or last names.
Right now, what I have is a working solution for one column (i.e.) I can populate the AutoCompleteSource with the firstName alone (or lastName alone) and then the search would work on that. In the above example, that means typing G would give "Goat" as a suggestion - Note, it does not suggest firstName + lastName.
The current code looks like so:
nameTextBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
nameTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
// Retrieve all rows
cmd.CommandText = "SELECT * FROM users";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
collection.Add(reader["firstName"].ToString());
}
}
nameTextBox.AutoCompleteCustomSource = collection;
Does the auto-complete in C# support this feature? Or is adding a hidden listbox below the textbox and populating the values there manually using the search string the only way of doing this?