How to make sure ComboBox select nothing...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Programatix

    How to make sure ComboBox select nothing...

    Hi,

    I'm having problem with ComboBox. I'm trying to force the ComboBox select
    nothing by doing this,
    myCombo.Selecte dText = ""
    myCombo.Selecte dIndex = -1
    but in vain, as the ComboBox will automatically select the first available
    selection.

    If I make the ComboBox visible before setting the .SelectedText to "" and
    the .SelectedIndex property to -1, it will be successful. But if I put the
    ComboBox in a TabControl and I switch between the Tabs in the TabControl,
    the ComboBox will automatically reselect the first available selection.

    Anyone out there has a solution?

    Thanks in advance.


  • Juan C. Olivares

    #2
    Re: How to make sure ComboBox select nothing...

    Add an empty object to the combobox options :)

    "Programati x" <programatix@no spam.com> escribió en el mensaje
    news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    >
    > I'm having problem with ComboBox. I'm trying to force the ComboBox select
    > nothing by doing this,
    > myCombo.Selecte dText = ""
    > myCombo.Selecte dIndex = -1
    > but in vain, as the ComboBox will automatically select the first available
    > selection.
    >
    > If I make the ComboBox visible before setting the .SelectedText to "" and
    > the .SelectedIndex property to -1, it will be successful. But if I put the
    > ComboBox in a TabControl and I switch between the Tabs in the TabControl,
    > the ComboBox will automatically reselect the first available selection.
    >
    > Anyone out there has a solution?
    >
    > Thanks in advance.
    >
    >[/color]


    Comment

    • Herfried K. Wagner

      #3
      Re: How to make sure ComboBox select nothing...

      Hello,

      "Programati x" <programatix@no spam.com> schrieb:[color=blue]
      > I'm having problem with ComboBox. I'm trying to force the
      > ComboBox select
      > nothing by doing this,
      > myCombo.Selecte dText = ""
      > myCombo.Selecte dIndex = -1
      > but in vain, as the ComboBox will automatically select
      > the first available selection.[/color]

      Try to call "myCombo.Select edIndex = -1" twice, somethimes that helps.

      Regards,
      Herfried K. Wagner
      --
      MVP · VB Classic, VB .NET
      Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



      Comment

      • Programatix

        #4
        Re: How to make sure ComboBox select nothing...

        What if I binded the ComboBox to a DataSource?

        Thanks for the respond.

        "Juan C. Olivares" <juancri@TAGnet .org> wrote in message
        news:eD9yrVRTDH A.560@TK2MSFTNG P10.phx.gbl...[color=blue]
        > Add an empty object to the combobox options :)
        >
        > "Programati x" <programatix@no spam.com> escribió en el mensaje
        > news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=green]
        > > Hi,
        > >
        > > I'm having problem with ComboBox. I'm trying to force the ComboBox[/color][/color]
        select[color=blue][color=green]
        > > nothing by doing this,
        > > myCombo.Selecte dText = ""
        > > myCombo.Selecte dIndex = -1
        > > but in vain, as the ComboBox will automatically select the first[/color][/color]
        available[color=blue][color=green]
        > > selection.
        > >
        > > If I make the ComboBox visible before setting the .SelectedText to ""[/color][/color]
        and[color=blue][color=green]
        > > the .SelectedIndex property to -1, it will be successful. But if I put[/color][/color]
        the[color=blue][color=green]
        > > ComboBox in a TabControl and I switch between the Tabs in the[/color][/color]
        TabControl,[color=blue][color=green]
        > > the ComboBox will automatically reselect the first available selection.
        > >
        > > Anyone out there has a solution?
        > >
        > > Thanks in advance.
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Programatix

          #5
          Re: How to make sure ComboBox select nothing...

          It did, but as I have state, if I put the ComboBox into a TabControl and
          switched between the Tabs in the TabControl, the ComboBox will reselect the
          first available option.

          I'm thinking of expanding the ComboBox by inheriting it but could not think
          of a way to code it. Any idea?

          "Herfried K. Wagner" <hirf.nosp@m.ac tivevb.de> wrote in message
          news:%23vr9kxST DHA.3796@tk2msf tngp13.phx.gbl. ..[color=blue]
          > Hello,
          >
          > "Programati x" <programatix@no spam.com> schrieb:[color=green]
          > > I'm having problem with ComboBox. I'm trying to force the
          > > ComboBox select
          > > nothing by doing this,
          > > myCombo.Selecte dText = ""
          > > myCombo.Selecte dIndex = -1
          > > but in vain, as the ComboBox will automatically select
          > > the first available selection.[/color]
          >
          > Try to call "myCombo.Select edIndex = -1" twice, somethimes that helps.
          >
          > Regards,
          > Herfried K. Wagner
          > --
          > MVP · VB Classic, VB .NET
          > http://www.mvps.org/dotnet
          >
          >[/color]


          Comment

          • Ron McNulty

            #6
            Re: How to make sure ComboBox select nothing...

            I select the records into a dataset, then add a row with a description of
            "<None>" and a value of DbNull.Value. Then I bind the combo box to that
            dataset.

            This lets users actually put a null in the database when appropriate. I
            don't think your current efforts will achieve this.

            Regards

            Ron

            "Programati x" <programatix@no spam.com> wrote in message
            news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=blue]
            > Hi,
            >
            > I'm having problem with ComboBox. I'm trying to force the ComboBox select
            > nothing by doing this,
            > myCombo.Selecte dText = ""
            > myCombo.Selecte dIndex = -1
            > but in vain, as the ComboBox will automatically select the first available
            > selection.
            >
            > If I make the ComboBox visible before setting the .SelectedText to "" and
            > the .SelectedIndex property to -1, it will be successful. But if I put the
            > ComboBox in a TabControl and I switch between the Tabs in the TabControl,
            > the ComboBox will automatically reselect the first available selection.
            >
            > Anyone out there has a solution?
            >
            > Thanks in advance.
            >
            >[/color]


            Comment

            • Programatix

              #7
              Re: How to make sure ComboBox select nothing...

              That's a great idea. How come I never thought of that.
              Thanks.

              "Ron McNulty" <rmcnulty@xtra. co.nz> wrote in message
              news:Ov4VrRYTDH A.2252@TK2MSFTN GP12.phx.gbl...[color=blue]
              > I select the records into a dataset, then add a row with a description of
              > "<None>" and a value of DbNull.Value. Then I bind the combo box to that
              > dataset.
              >
              > This lets users actually put a null in the database when appropriate. I
              > don't think your current efforts will achieve this.
              >
              > Regards
              >
              > Ron
              >
              > "Programati x" <programatix@no spam.com> wrote in message
              > news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=green]
              > > Hi,
              > >
              > > I'm having problem with ComboBox. I'm trying to force the ComboBox[/color][/color]
              select[color=blue][color=green]
              > > nothing by doing this,
              > > myCombo.Selecte dText = ""
              > > myCombo.Selecte dIndex = -1
              > > but in vain, as the ComboBox will automatically select the first[/color][/color]
              available[color=blue][color=green]
              > > selection.
              > >
              > > If I make the ComboBox visible before setting the .SelectedText to ""[/color][/color]
              and[color=blue][color=green]
              > > the .SelectedIndex property to -1, it will be successful. But if I put[/color][/color]
              the[color=blue][color=green]
              > > ComboBox in a TabControl and I switch between the Tabs in the[/color][/color]
              TabControl,[color=blue][color=green]
              > > the ComboBox will automatically reselect the first available selection.
              > >
              > > Anyone out there has a solution?
              > >
              > > Thanks in advance.
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Joe White

                #8
                Re: How to make sure ComboBox select nothing...

                Okay, here's kind of a crazy idea (but one that ought to work): Create
                your own class that implements IList. In your class's constructor, take
                a parameter of type IListSource; call IListSource.Get List(), and save a
                reference to the IList that's returned. Then implement your class's
                IList.Count property to return savedList.Count + 1, and have your
                IList.Item property return "" for element 0, and otherwise return
                savedList[index - 1]. Then create an instance of this class, passing
                your DataTable as a parameter to the constructor; and bind your ComboBox
                to this object, instead of directly to the DataTable.

                Sounds like a bit of a pain, until you consider that you can then re-use
                this same class for every combo box in your application...


                Programatix wrote:[color=blue]
                > Ok, there's a problem. I'm using DataRelation. The child Table will use the
                > primary key column of the parent Table as the value. Since it's a primary
                > key, I cannot add a NULL value for it.
                >
                > Sigh...
                >
                > "Ron McNulty" <rmcnulty@xtra. co.nz> wrote in message
                > news:Ov4VrRYTDH A.2252@TK2MSFTN GP12.phx.gbl...
                >[color=green]
                >>I select the records into a dataset, then add a row with a description of
                >>"<None>" and a value of DbNull.Value. Then I bind the combo box to that
                >>dataset.
                >>
                >>This lets users actually put a null in the database when appropriate. I
                >>don't think your current efforts will achieve this.
                >>
                >>Regards
                >>
                >>Ron
                >>
                >>"Programati x" <programatix@no spam.com> wrote in message
                >>news:uXodN9QT DHA.3192@tk2msf tngp13.phx.gbl. ..
                >>[color=darkred]
                >>>Hi,
                >>>
                >>>I'm having problem with ComboBox. I'm trying to force the ComboBox[/color]
                >>[/color]
                > select
                >[color=green][color=darkred]
                >>>nothing by doing this,
                >>> myCombo.Selecte dText = ""
                >>> myCombo.Selecte dIndex = -1
                >>>but in vain, as the ComboBox will automatically select the first[/color]
                >>[/color]
                > available
                >[color=green][color=darkred]
                >>>selection.
                >>>
                >>>If I make the ComboBox visible before setting the .SelectedText to ""[/color]
                >>[/color]
                > and
                >[color=green][color=darkred]
                >>>the .SelectedIndex property to -1, it will be successful. But if I put[/color]
                >>[/color]
                > the
                >[color=green][color=darkred]
                >>>ComboBox in a TabControl and I switch between the Tabs in the[/color]
                >>[/color]
                > TabControl,
                >[color=green][color=darkred]
                >>>the ComboBox will automatically reselect the first available selection.
                >>>
                >>>Anyone out there has a solution?
                >>>
                >>>Thanks in advance.[/color][/color][/color]

                Comment

                • Claes Bergefall

                  #9
                  Re: How to make sure ComboBox select nothing...

                  Sounds like you're binding to it
                  That causes problems with controls on tab controls

                  Read this:


                  Basically you need to add the following during the loading
                  of your form (tabpage is the one containing your combo)
                  tabpage.Binding Context = form.BindingCon text


                  Also read this:
                  Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.



                  /claes

                  "Programati x" <programatix@no spam.com> wrote in message
                  news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=blue]
                  > Hi,
                  >
                  > I'm having problem with ComboBox. I'm trying to force the ComboBox select
                  > nothing by doing this,
                  > myCombo.Selecte dText = ""
                  > myCombo.Selecte dIndex = -1
                  > but in vain, as the ComboBox will automatically select the first available
                  > selection.
                  >
                  > If I make the ComboBox visible before setting the .SelectedText to "" and
                  > the .SelectedIndex property to -1, it will be successful. But if I put the
                  > ComboBox in a TabControl and I switch between the Tabs in the TabControl,
                  > the ComboBox will automatically reselect the first available selection.
                  >
                  > Anyone out there has a solution?
                  >
                  > Thanks in advance.
                  >
                  >[/color]


                  Comment

                  • Programatix

                    #10
                    Re: How to make sure ComboBox select nothing...

                    Mmmm, the article at http://support.microsoft.com/?id=327244 explain that
                    the bug is found in .NetFramework 1.0. Since I'm using .NetFramework 1.1,
                    this means that the bug is not fixed yet.

                    For the solution found in http://noiseehc.freeweb.hu/CurrencyManager.html,
                    I'll try it right away.

                    Thanks for the reference.


                    "Claes Bergefall" <claes.bergefal l.nospam@fronte c.se> wrote in message
                    news:OwWpE12TDH A.2460@TK2MSFTN GP10.phx.gbl...[color=blue]
                    > Sounds like you're binding to it
                    > That causes problems with controls on tab controls
                    >
                    > Read this:
                    > http://noiseehc.freeweb.hu/CurrencyManager.html
                    >
                    > Basically you need to add the following during the loading
                    > of your form (tabpage is the one containing your combo)
                    > tabpage.Binding Context = form.BindingCon text
                    >
                    >
                    > Also read this:
                    > http://support.microsoft.com/?id=327244
                    >
                    >
                    > /claes
                    >
                    > "Programati x" <programatix@no spam.com> wrote in message
                    > news:uXodN9QTDH A.3192@tk2msftn gp13.phx.gbl...[color=green]
                    > > Hi,
                    > >
                    > > I'm having problem with ComboBox. I'm trying to force the ComboBox[/color][/color]
                    select[color=blue][color=green]
                    > > nothing by doing this,
                    > > myCombo.Selecte dText = ""
                    > > myCombo.Selecte dIndex = -1
                    > > but in vain, as the ComboBox will automatically select the first[/color][/color]
                    available[color=blue][color=green]
                    > > selection.
                    > >
                    > > If I make the ComboBox visible before setting the .SelectedText to ""[/color][/color]
                    and[color=blue][color=green]
                    > > the .SelectedIndex property to -1, it will be successful. But if I put[/color][/color]
                    the[color=blue][color=green]
                    > > ComboBox in a TabControl and I switch between the Tabs in the[/color][/color]
                    TabControl,[color=blue][color=green]
                    > > the ComboBox will automatically reselect the first available selection.
                    > >
                    > > Anyone out there has a solution?
                    > >
                    > > Thanks in advance.
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    Working...