ComboBox's SelectedIndex Property problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric A. Johnson

    #1

    ComboBox's SelectedIndex Property problem

    Hi Everyone,

    I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
    need to use in order to select a query for my database project. Therefore,
    I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a new
    selection is made, update the query and refresh the display. The only
    problem is that the program seems to inexplicably start with the
    ..selectedindex property at -1! This makes no sense to me. Furthermore,
    this is, apparently, happening *before* my form loads, as not only does the
    form not appear on screen, but even when I put a breakpoint at the first
    possible line within the form_load handler, it still crashes; the breakpoint
    is never even reached. Is there a way to locate the point at which the
    property is being changed to (or created with) the value of -1? It seems to
    me that it should not happen at all.
    Please respond here, if possible; if you need more info, you can reach
    me via AIM at ajeric74. Thank you!

    -- Eric


  • Qwert

    #2
    Re: ComboBox's SelectedIndex Property problem

    Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
    Then cmbComboBox.Sel ectedIndex is -1 (default value)

    You get an error if you would try this:
    Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
    cmbComboBox.Sel ectedIndex = 0

    Can't you exit event _SelectedIndexC hanged when the index is invalid?

    With cmbComboBox
    If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
    Exit Sub
    End If
    End With


    "Eric A. Johnson" <nothere@dontlo okforme.com> schreef in bericht
    news:7Q_4f.1722 4$6e1.7021@news svr14.news.prod igy.com...[color=blue]
    > Hi Everyone,
    >
    > I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
    > need to use in order to select a query for my database project.
    > Therefore,
    > I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a new
    > selection is made, update the query and refresh the display. The only
    > problem is that the program seems to inexplicably start with the
    > .selectedindex property at -1! This makes no sense to me. Furthermore,
    > this is, apparently, happening *before* my form loads, as not only does
    > the
    > form not appear on screen, but even when I put a breakpoint at the first
    > possible line within the form_load handler, it still crashes; the
    > breakpoint
    > is never even reached. Is there a way to locate the point at which the
    > property is being changed to (or created with) the value of -1? It seems
    > to
    > me that it should not happen at all.
    > Please respond here, if possible; if you need more info, you can reach
    > me via AIM at ajeric74. Thank you!
    >
    > -- Eric
    >
    >[/color]


    Comment

    • Boo K.M.

      #3
      Re: ComboBox's SelectedIndex Property problem


      "Qwert" <nosp@nosp.co m> wrote in message
      news:WcmdncnKMp RmB8neRVnyrA@ca sema.nl...[color=blue]
      > Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
      > Then cmbComboBox.Sel ectedIndex is -1 (default value)
      >
      > You get an error if you would try this:
      > Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
      > cmbComboBox.Sel ectedIndex = 0
      >
      > Can't you exit event _SelectedIndexC hanged when the index is invalid?
      >
      > With cmbComboBox
      > If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
      > Exit Sub
      > End If
      > End With
      >
      >[/color]

      I would like to ask for a side question.
      If that is -1 (by default), how do I set the combo text when there is no
      selection? Something like web pages "(Please choose a category from
      list)"...

      That will help a lot. TIA.

      Boo K.M.


      Comment

      • ECathell

        #4
        Re: ComboBox's SelectedIndex Property problem

        Better form would be

        If not me.cmbComboBox. selectedindex=-1 then
        'do something
        end if

        put that inside your handler....


        --
        --Eric Cathell, MCSA
        "Qwert" <nosp@nosp.co m> wrote in message
        news:WcmdncnKMp RmB8neRVnyrA@ca sema.nl...[color=blue]
        > Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
        > Then cmbComboBox.Sel ectedIndex is -1 (default value)
        >
        > You get an error if you would try this:
        > Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
        > cmbComboBox.Sel ectedIndex = 0
        >
        > Can't you exit event _SelectedIndexC hanged when the index is invalid?
        >
        > With cmbComboBox
        > If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
        > Exit Sub
        > End If
        > End With
        >
        >
        > "Eric A. Johnson" <nothere@dontlo okforme.com> schreef in bericht
        > news:7Q_4f.1722 4$6e1.7021@news svr14.news.prod igy.com...[color=green]
        >> Hi Everyone,
        >>
        >> I am at my wit's end here. I have a combobox (combyQueryTitl e) that I
        >> need to use in order to select a query for my database project.
        >> Therefore,
        >> I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a
        >> new
        >> selection is made, update the query and refresh the display. The only
        >> problem is that the program seems to inexplicably start with the
        >> .selectedindex property at -1! This makes no sense to me. Furthermore,
        >> this is, apparently, happening *before* my form loads, as not only does
        >> the
        >> form not appear on screen, but even when I put a breakpoint at the first
        >> possible line within the form_load handler, it still crashes; the
        >> breakpoint
        >> is never even reached. Is there a way to locate the point at which the
        >> property is being changed to (or created with) the value of -1? It seems
        >> to
        >> me that it should not happen at all.
        >> Please respond here, if possible; if you need more info, you can reach
        >> me via AIM at ajeric74. Thank you!
        >>
        >> -- Eric
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • ECathell

          #5
          Re: ComboBox's SelectedIndex Property problem

          Hard code that as your first selection. Then when you bind the datasource it
          should fill in under that selection.

          -1 means the control is initializing or is stateless(I think I read that on
          MSDN) Once the form is loaded the default index=0

          combo box's can be a pain....


          --
          --Eric Cathell, MCSA
          "Boo K.M." <boo_k.m.NOSPAM @bkm-researcher.com> wrote in message
          news:4354b819_2 @news.tm.net.my ...[color=blue]
          >
          > "Qwert" <nosp@nosp.co m> wrote in message
          > news:WcmdncnKMp RmB8neRVnyrA@ca sema.nl...[color=green]
          >> Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
          >> Then cmbComboBox.Sel ectedIndex is -1 (default value)
          >>
          >> You get an error if you would try this:
          >> Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
          >> cmbComboBox.Sel ectedIndex = 0
          >>
          >> Can't you exit event _SelectedIndexC hanged when the index is invalid?
          >>
          >> With cmbComboBox
          >> If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
          >> Exit Sub
          >> End If
          >> End With
          >>
          >>[/color]
          >
          > I would like to ask for a side question.
          > If that is -1 (by default), how do I set the combo text when there is no
          > selection? Something like web pages "(Please choose a category from
          > list)"...
          >
          > That will help a lot. TIA.
          >
          > Boo K.M.
          >[/color]


          Comment

          • ECathell

            #6
            Re: ComboBox's SelectedIndex Property problem

            I think you actually want to use .text value. Actually you can databind the
            same combobox to 2 different datasources. So if you have a table that has
            the query name, query you could do something like this

            cbo.datasource= table
            cbo.diplaymembe r=column0name
            cbo.databinding .add(new binding("text", table,"column0n ame)
            cbo.databinding .add(new binding("valuem ember",table,"c olumn1name)

            then you would be able to get the querystring off the .selectedvalue
            property.

            Play around with it some, I ALWAYS have to tinker with my comboboxes because
            it always seems each situation needs a different approach. Combos are a
            pain...but thats because they are very powerful.


            --
            --Eric Cathell, MCSA
            "Eric A. Johnson" <nothere@dontlo okforme.com> wrote in message
            news:g%k5f.1741 8$6e1.5498@news svr14.news.prod igy.com...[color=blue]
            > As a matter of fact, is it possible to get the text associated with an
            > index within the combobox without actually modifying the .selectedindex
            > property? It is extremely annoying, trying to change within the program
            > code the selected index, only to have it crash because... I don't even
            > know why. I can't understand why it won't allow me to change the selected
            > index! The tooltip in VB.NET tells me that the .selectedindex method
            > allows me to get or set the index that is selected. Maybe if someone can
            > point me to a detailed explanation of this idiotic behavior and how to
            > work around it? I just want the invisible combobox's index to be the same
            > as the visible one. My AIM name is ajeric74... SOMEBODY please come online
            > to help me!!!
            >
            > -- Eric
            >
            > "Eric A. Johnson" <nothere@dontlo okforme.com> wrote in message
            > news:vMk5f.1741 5$6e1.185@newss vr14.news.prodi gy.com...[color=green]
            >> Okay, I have another question: What I'm trying to do is to use an
            >> ordinary combobox to hold the query title, and an invisible combobox to
            >> hold the actual query. I want to make it so that the invisible combobox
            >> will change to match the visible one, thereby allowing its .text property
            >> to contain the proper query. Is that possible?
            >>
            >> TIA,
            >> Eric
            >>
            >> "ECathell" <ecathell@nospa m.com> wrote in message
            >> news:Ogobw0%230 FHA.1564@tk2msf tngp13.phx.gbl. ..[color=darkred]
            >>> Better form would be
            >>>
            >>> If not me.cmbComboBox. selectedindex=-1 then
            >>> 'do something
            >>> end if
            >>>
            >>> put that inside your handler....
            >>>
            >>>
            >>> --
            >>> --Eric Cathell, MCSA
            >>> "Qwert" <nosp@nosp.co m> wrote in message
            >>> news:WcmdncnKMp RmB8neRVnyrA@ca sema.nl...
            >>>> Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
            >>>> Then cmbComboBox.Sel ectedIndex is -1 (default value)
            >>>>
            >>>> You get an error if you would try this:
            >>>> Me.cmbComboBox= New System.Windows. Forms.ComboBox( )
            >>>> cmbComboBox.Sel ectedIndex = 0
            >>>>
            >>>> Can't you exit event _SelectedIndexC hanged when the index is invalid?
            >>>>
            >>>> With cmbComboBox
            >>>> If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
            >>>> Exit Sub
            >>>> End If
            >>>> End With
            >>>>
            >>>>
            >>>> "Eric A. Johnson" <nothere@dontlo okforme.com> schreef in bericht
            >>>> news:7Q_4f.1722 4$6e1.7021@news svr14.news.prod igy.com...
            >>>>> Hi Everyone,
            >>>>>
            >>>>> I am at my wit's end here. I have a combobox (combyQueryTitl e)
            >>>>> that I
            >>>>> need to use in order to select a query for my database project.
            >>>>> Therefore,
            >>>>> I am using the comboQueryTitle _SelectedIndexC hanged handler to, when a
            >>>>> new
            >>>>> selection is made, update the query and refresh the display. The only
            >>>>> problem is that the program seems to inexplicably start with the
            >>>>> .selectedindex property at -1! This makes no sense to me.
            >>>>> Furthermore,
            >>>>> this is, apparently, happening *before* my form loads, as not only
            >>>>> does the
            >>>>> form not appear on screen, but even when I put a breakpoint at the
            >>>>> first
            >>>>> possible line within the form_load handler, it still crashes; the
            >>>>> breakpoint
            >>>>> is never even reached. Is there a way to locate the point at which
            >>>>> the
            >>>>> property is being changed to (or created with) the value of -1? It
            >>>>> seems to
            >>>>> me that it should not happen at all.
            >>>>> Please respond here, if possible; if you need more info, you can
            >>>>> reach
            >>>>> me via AIM at ajeric74. Thank you!
            >>>>>
            >>>>> -- Eric
            >>>>>
            >>>>>
            >>>>
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            Working...