Results 1 to 7 of 7

Thread: [2.0] Trigger combobox dropdown list

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    [2.0] Trigger combobox dropdown list

    Anyone know how to programmatically pop open a combobox's dropdown list. Ideally i want it perminantly open.
    Last edited by SLH; Apr 22nd, 2006 at 01:10 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Drigger combobox dropdown list

    You should set the DropDownStyle to Simple at design time if you want the list permanently visible. You can set the DroppedDown property to True to drop the list programmatically but it will disappear again as soon as the user clicks somewhere.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2.0] Drigger combobox dropdown list

    If you want it open permanently, why not use a Listbox instead of a combo?

    (Congrats on 10K jmcilhinney )

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Drigger combobox dropdown list

    Quote Originally Posted by Hack
    If you want it open permanently, why not use a Listbox instead of a combo?

    (Congrats on 10K jmcilhinney )
    The advantage of a Simple ComboBox is that you can type in anything that you want, or select from the list, just like a DropDown ComboBox. A ListBox is like a DropDownList ComboBox, where you can only choose from the items in the list. If that's what you want then you should use a ListBox as Hack suggests.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2.0] Drigger combobox dropdown list

    I changed the style to 'simple' and changing the member variable as you said didn't work. Changing the styly to 'dropdown' did though, so thanks for that.

    I've got another problem now though. All i did was add the line 'cboRunThis.DroppedDown = true;' in my text changed event and now the mouse disappears when it's over my program.

    I guess the problem is that i'm updating the list in a seperate thread, but i'm doing that ok i think (by calling invoke if required, using code from MSDN). It doesn't make the cursor disappear if i manually click the combobox to show the list, plus the list is updated as appropriate then.

    I'm just not sure why it should be a problem when i'm updating the list in another thread.

    Any thoughts on this would be appreciated.

    EDIT:

    Now as soon as the list had items then has none i get the following error...

    Code:
    System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'index'.
    Parameter name: index
       at System.Windows.Forms.ComboBox.ObjectCollection.get_Item(Int32 index)
       at System.Windows.Forms.ComboBox.get_Text()
       at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
       at System.Windows.Forms.ComboBox.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    I have no idea what could be wrong with my code, since that isn't my code.
    I've tried removing every line where i dropdown the list, so i'm really stumped as to what's going wrong. I guess it's to do with the way i'm updating the list, so here's the code my thread is using to update the list.

    Code:
    public void AddItem(string Item, ComboBox DisplayBox)
            {
                if (DisplayBox.InvokeRequired)
                {
                    AddItemCallback CallBack = new AddItemCallback(AddItem);
                    this.Invoke(CallBack, new object[] { Item, DisplayBox });
                }
                else
                {
                    int CursorPos = DisplayBox.SelectionStart;
                    DisplayBox.Items.Add(Item);
                    DisplayBox.SelectionStart = CursorPos;
                }
            }
    and here's the code i use in the textchanged event that clears the combobox's list, and aborts the worker thread (and creates a new worker thread).

    Code:
    private void cboRunThis_TextChanged(object sender, EventArgs e)
            {
                WorkerParameters Params = new WorkerParameters();
                if (WorkerThread.IsAlive)
                {
                    WorkerThread.Abort();
                    WorkerThread.Join();
                }
                if (cboRunThis.Text.Length == 0)
                    return;
                FoundItemsQueue.Clear();
                int CursorPos = cboRunThis.SelectionStart;
                cboRunThis.Items.Clear();
                cboRunThis.SelectionStart = CursorPos;
    
                if (cboRunThis.Text.Contains("/"))
                    return;
                WorkerThread = new Thread(Job);
                Params.SearchString = cboRunThis.Text;
                Params.DisplayBox = cboRunThis;
                WorkerThread.Start(Params);
            }
    Last edited by SLH; Apr 21st, 2006 at 10:40 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Drigger combobox dropdown list

    I think you're going about this all wrong. I think what you probably should be doing is using the autocomplete features of WinForms 2.0. Take a look at the properties of the TextBox and ComboBox that start with "AutoComplete".

    Also, that call to Join looks a bit dodgy. If you Join the worker thread then your UI thread stops executing until the worker thread completes. That's probably why you're losing your cursor.
    Last edited by jmcilhinney; Apr 21st, 2006 at 11:40 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2.0] Drigger combobox dropdown list

    I can't really use auto complete since the items in the list done always begin with what the user types in (plus it seems that if i change the list on the fly, changing the autocompletecustom string collection it crashes if it's being displayed).

    The second point, the call do join is fine since i'm aborting the thread just before i join it (so basically i trigger the thread to be terminated , then wait for it to end).
    The cursor problem was happening before i added the join command (in fact i added it hoping that was the causing the wierd crashing!).

    Thanks for your input though, it's greatly appreciated!
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width