Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Combobox event handler question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Resolved [RESOLVED] [2005] Combobox event handler question

    Greetings All,

    This question has been batted around a bit in this forum, but this issue still confuses me.

    I have a combobox that is on a panel, which is on a panel, which is on a form tab. I am pragmatically filling the combobox and I can successfully select a value and display another in the combobox.

    What I can not do is get an event handler to fire when the user makes a pick from the combobox. I believe that the panels or the form tab events are overriding the combobox events and have tried toth use em, but with no success. Any suggestions?

    Thanks in advance for your thoughts.

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

    Re: [2005] Combobox event handler question

    There is no interference of events. If you add a ComboBox to a form then the IDE creates a member variable for that control. When you create an event handler it is for that variable. Whether the ComboBox is nested in a thousand containers makes no difference. If you can provide the exact steps to reproduce your issue and specify exactly what the issue is then we can have a look at it.
    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
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2005] Combobox event handler question

    I put in combo in a panel in a panel and handled the SelectedIndexChanged event - no problem. What event are you handling?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Re: [2005] Combobox event handler question

    I have tried every event handler possibility (that is reasonable) and none will handle the event. The combobox is not bound to anything and is filled programmatically:
    Code:
            view1.Table = Me.ScoreboardDataSet.tbl_Schools
            view2.Table = Me.ScoreboardDataSet.tbl_Schools
    
            With Me.ComboBox5
                .Items.Clear()
                .DropDownStyle = ComboBoxStyle.DropDownList
                .DataSource = view1
                .DisplayMember = "SName"
                .ValueMember = "SchoolID"
                '.SelectedIndex = 0    NOT USED
                '.SelectedValue = row("GTeamID")   NOT USED
            End With
    
            With Me.ComboBox4
                .Items.Clear()
                .DropDownStyle = ComboBoxStyle.DropDownList
                .DataSource = view2
                .DisplayMember = "SName"
                .ValueMember = "SchoolID"
                '.SelectedIndex = 0    NOT USED
                '.SelectedValue = CStr(row("RTeamID"))    NOT USED
            End With
    The Combobox events look similar to:

    Code:
       Private Sub ComboBox5_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox5.SelectedIndexChanged
            AddGSchoolData()
        End Sub
    I can not find an event handler that seams to work correctly.

    I have put a test button on the form using the code behind AddSchoolData() and it runs fine. There are two similar Comboboxes on the form, both filled the same way, and neither will handle an event. Attached is a snapshot of the property pane for one of the comboboxes.

    This seams simple… what information can I provide that will help explain?
    Attached Images Attached Images  

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

    Re: [2005] Combobox event handler question

    I said:
    If you can provide the exact steps to reproduce your issue and specify exactly what the issue is then we can have a look at it.
    You haven't.
    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

  6. #6
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2005] Combobox event handler question

    I am a little suspicious that you have set the datasource and yet claim that the control is not bound to anything? Surely, it is bound to the datasource (View1 or View2)?

    Anway, to convince yourself that your problem has nothing to do with the panel-within-a-panel, why not set up a simple combo box, put simple data into its items collection, and then handle the SelectedIndexChanged event? At least your mind will be put to rest that your problem does not stem from the fact of nested controls.

    Btw - are the list portions of the controls filling properly? If they are, try to capture a mouseclick event, something that does not depend upon the list part of the control.

    I am interested in this problem, pls keep us informed. Good luck.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Smile Re: [2005] Combobox event handler question

    Jmcilhinney- you are right. I did not provide what you requested. I was hoping that I provided enough information to get a suggestion (or a hint) without making others dizzy with my crazy code. I should have posted more- I will do better with my next question.

    bigMeUp- I took your suggestion and placed a simple combobox, with a simple collection, and used the SelectedIndexChanged event to write some text to a textbox on the form. Worked Perfect. I then replaced the AddGSchoolData() call in my code for the other combobox with the simple “write some text to a textbox” and it worked as well. The event handler for the other comboboxes were firing all along.

    My issue was that the combobox SelectedIndexChanged event handler was firing as the form was opening and my AddGSchoolData() sub would run before I had other data in place. While this was not throwing an error, it was disabling the event handler (at least that is how I perceive it). My fix for this was to remove the “Handles SelectedIndexChanged” from the sub ComboBox5_SelectedIndexChanged and use the AddHandler method to attach the event handler in the form_load sub.
    Code:
    AddHandler ComboBox5.SelectedIndexChanged, AddressOf ComboBox5_SelectedIndexChanged
    Everything works fine. Thanks for the help.

    Another question though- You questioned if I had the comboboxes bound to any datasources. I used the following code to populate two ComboBoxes. I used the word “populated”, is it correct to say that I bound the ComboBoxes to view1.Table and view2.Table with this code?

    Code:
           view1.Table = Me.ScoreboardDataSet.tbl_Schools
            view2.Table = Me.ScoreboardDataSet.tbl_Schools
    
            With Me.ComboBox5
                .Items.Clear()
                .DropDownStyle = ComboBoxStyle.DropDownList
                .DataSource = view1
                .DisplayMember = "SName"
                .ValueMember = "SchoolID"
                '.SelectedIndex = 0    NOT USED
                '.SelectedValue = row("GTeamID")   NOT USED
            End With
    
            With Me.ComboBox4
                .Items.Clear()
                .DropDownStyle = ComboBoxStyle.DropDownList
                .DataSource = view2
                .DisplayMember = "SName"
                .ValueMember = "SchoolID"
                '.SelectedIndex = 0    NOT USED
                '.SelectedValue = CStr(row("RTeamID"))    NOT USED
            End With

  8. #8
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    UK
    Posts
    285

    Re: [2005] Combobox event handler question

    I am glad your problem has been solved. No doubt, you will soon be marking this thread *Resolved*

    I would certainly say that a control which has its data linked to a data source is definitely a bound control. If anyone disagrees, it would be interesting to hear why.

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