Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2007, 11:56 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default SOLVED -- Overriding OnTextChanged of ComboBox

Hey all,
    I have created an AutoComplete ComboBox that is working beautifully, a user inputs text a string that is similar to their text is returned etc.

Well, my boss has informed me that he wants the list of items to change accordingly to what is keyed into the Combo Box so if a user inputs an 'F' the list will resize to only items containing F.

This is my problem. I can resize the list based upon what is keyed into the combo box BUT i call [combobox].items.clear(); then repopulate the list with the subset of data.

After calling [combobox].items.clear(); my autocomplete methods stop working because all of my calls to FindString, FindExactString, etc return 0 and -1, respectively.

This obviously has to do with me resizing the list but is there any way around it?

I have used [combobox].items.add as well as DataBindings to add items to the list in an attempt to circumvent my problem, but to no avail!
Any help would be greatly appreciated.



================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old January 17th, 2007, 02:50 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok, this actually turned out to be much simpler then I was making it out to be. Instead of handling the TextChanged event I instead handled the KeyUp event. This works like a charm:

        private void OnKeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if(e.KeyCode != Keys.Back && e.KeyCode != Keys.Delete && e.KeyCode != Keys.Shift && e.KeyCode != Keys.Home && e.KeyCode != Keys.Left && e.KeyCode != Keys.Right)
            {
                string input = comboBox2.Text;
                sSql = "SQL Statement";
                dt = da.getDataTable(sSql);

                if(dt.Rows.Count != 0)
                {
                    comboBox2.Items.Clear();
                    foreach(DataRow dr in dt.Rows)
                    {
                        comboBox2.Items.Add(dr["Name"]);
                    }
                }


                int index = comboBox2.FindString(input);
                if(index != -1)
                {
                    comboBox2.SelectedIndex = index;
                    comboBox2.Select(input.Length, comboBox2.Text.Length);
                }
            }

        }

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Solved - rs.FindFirst and Multiple Column ComboBox eusanpe Access VBA 1 May 20th, 2008 03:21 PM
Solved-RS.FindFirst and Multiple Column ComboBox eusanpe Access VBA 0 May 19th, 2008 01:25 PM
Overriding the TreeView Control Aaron Edwards ASP.NET 2.0 Basics 0 January 27th, 2006 05:48 PM
Overloading Overriding arv1980 VS.NET 2002/2003 2 January 22nd, 2006 12:55 AM
Overriding arv1980 VS.NET 2002/2003 0 January 21st, 2006 09:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.