Donate

AutoComplete Winforms Search Not Working If Search Item Is One Character Digit In C#

Textbox properites: autocompletemode = append, autcompletesource = customsource. Assuming the autocompletestringcollection of the textbox are as follows:

James
Philipp
Mariah
Clara
8
Ryan
GregEsguerra

If you type the number 8 in the textbox, the textbox autocomplete does not suggest. As defined, it will search the prefix of the source. So, i guess one character does not have a prefix at all. The workaround for this is to
add a space character after the digit 8. So, "8" becomes "8 ". Below is the code:
private void PopulateWebsiteName()  
      {  
        try  
        {  
          if (dtWebsiteNames != null) { dtWebsiteNames.Clear(); }  
          dtWebsiteNames = JobsReporting.Scripts.GetWebsiteNamesLocal();  
          if (dtWebsiteNames.Rows.Count > 0)  
          {  
            foreach (DataRow row in dtWebsiteNames.Rows)  
            {  
              if (row[1].ToString().Trim().Length == 1)   
              {  
                row[1] = row[1] + ' '.ToString();  
              }  
              websiteNameCollection.Add(Convert.ToString(row[1]));  
              website_id.Add(row[0].ToString());  
            }  
          }  
          txtWebsiteName.AutoCompleteCustomSource = websiteNameCollection;  
        }  
        catch (Exception e)  
        {   
         MessageBox.Show("Error Loading Website Names",   
         "", MessageBoxButtons.OK, MessageBoxIcon.Error);   
         }  
      }  
GetWebsiteNamesLocal() is the method to retrieve websites from the database.

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid