Tuesday, July 16, 2013

Add auto complete function for a textbox in your winform

auto complete is useful in a winform to, for example, help user to save time for type things such as username, to add auto listing to a textbox in a winform is very easy, below is an example code added to the Load delegate method in a winform:


            List<string> usernames = AccountManager.Instance.Usernames;
            if (usernames.Count > 0)
            {
                var source = new AutoCompleteStringCollection();
                foreach (string username in usernames)
                {
                    source.Add(username);
                }

                txtUsername.AutoCompleteCustomSource = source;
                txtUsername.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                txtUsername.AutoCompleteSource = AutoCompleteSource.CustomSource;
            }

No comments:

Post a Comment