Results 1 to 7 of 7

Thread: [2005] SelectedIndexChanged Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Question [2005] SelectedIndexChanged Problem

    Hi

    I have a combobox "cboPreviousPreparationEntries". Now I have a sub

    Private Sub cboPreviousPreparationEntries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreviousPreparationEntries.SelectedIndexChanged

    So this runs when the selected value of combo box is changed. Now for some reason in the code i need to put

    cboPreviousPreparationEntries.SelectedIndex = 2

    But at that time it calls the sub automatically as the index is changed, but I DO NOT WANT it to call that sub mentioned on top. Is that possible?

    I hope i made myself clear.

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

    Re: [2005] SelectedIndexChanged Problem

    Handle the SelectionChangeCommitted event instead, which is raised only when the user makes a change through the UI.
    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
    Lively Member Divine's Avatar
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    68

    Re: [2005] SelectedIndexChanged Problem

    What I'd do is just make a boolean (I made it public but you can send it through the function parameter list if you want):

    Code:
    Public ManualChange as Boolean = False
    Code:
    ManualChange = True
    cboPreviousPreparationEntries.SelectedIndex = 2
    Code:
    Private Sub cboPreviousPreparationEntries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreviousPreparationEntries.SelectedIndexChanged
    
    If ManualChange = True Then
    ManualChange = False
    'Rest of code
    End If
    But I guess you could optimize it.
    Wow that was easy. *slaps himself* I need to write that down.
    "He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever."

  4. #4
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: [2005] SelectedIndexChanged Problem

    Quote Originally Posted by jmcilhinney
    Handle the SelectionChangeCommitted event instead, which is raised only when the user makes a change through the UI.
    Can you elaborate on this? SelectionChangeCommitted does not appear to be an event of a combo box.

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

    Re: [2005] SelectedIndexChanged Problem

    Quote Originally Posted by nbrege
    Can you elaborate on this? SelectionChangeCommitted does not appear to be an event of a combo box.
    You are kidding aren't you? Where exactly have you looked to come to that conclusion? The screen shot below shows just four ways you could have found it and they are not the only ways either.
    Last edited by jmcilhinney; Feb 9th, 2008 at 04:13 AM.
    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
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: [2005] SelectedIndexChanged Problem

    My mistake. I was looking at a ToolStripComboBox. I assumed it would have the same events as a standard ComboBox control.

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

    Re: [2005] SelectedIndexChanged Problem

    Quote Originally Posted by nbrege
    My mistake. I was looking at a ToolStripComboBox. I assumed it would have the same events as a standard ComboBox control.
    A ToolStripComboBox is not a ComboBox. It is a ToolStripControlHost designed to host a ComboBox. It has a ComboBox property that refers to the ComboBox it's hosting. That ComboBox has a SelectionChangedCommitted event. Alternatively you could inherit the ToolStripComboBox class and add a SelectionChangeCommitted event.
    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

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