Selected text in a ComboBox

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

    #1

    Selected text in a ComboBox

    I have the following code:
    .cboBox1.Items. AddRange(New Object() {"A", "B", "C"})
    .cboBox2.Items. AddRange(New Object() {"A", "B", "C"})
    .cboBox6.Items. AddRange(New Object() {"A", "B", "C"})
    .cboBox1.Select edIndex = 0
    .cboBox2.Select edIndex = 1
    .cboBox6.Select edIndex = 2
    When this form opens, A, B, and C are all highlighted in their respective
    controls. I have tried the following ways to unhighlight the text but
    without success.

    .cboBox6.Select ionLength = 0
    .cboBox6.Select (0, 0)
    .cboBox1.Focus( )

    Is there a way to unhighlight the text in the comboboxes that do not have
    focus?

  • Some Guy

    #2
    Re: Selected text in a ComboBox

    Set them to -1
    .cboBox1.Select edIndex = -1
    .cboBox2.Select edIndex = -1
    .cboBox6.Select edIndex = -1



    "genojoe" <genojoe@discus sions.microsoft .com> wrote in message
    news:328CABAA-4A61-463C-88CB-EDEEBB871C1A@mi crosoft.com...[color=blue]
    >I have the following code:
    > .cboBox1.Items. AddRange(New Object() {"A", "B", "C"})
    > .cboBox2.Items. AddRange(New Object() {"A", "B", "C"})
    > .cboBox6.Items. AddRange(New Object() {"A", "B", "C"})
    > .cboBox1.Select edIndex = 0
    > .cboBox2.Select edIndex = 1
    > .cboBox6.Select edIndex = 2
    > When this form opens, A, B, and C are all highlighted in their respective
    > controls. I have tried the following ways to unhighlight the text but
    > without success.
    >
    > .cboBox6.Select ionLength = 0
    > .cboBox6.Select (0, 0)
    > .cboBox1.Focus( )
    >
    > Is there a way to unhighlight the text in the comboboxes that do not have
    > focus?
    >[/color]


    Comment

    • genojoe

      #3
      Re: Selected text in a ComboBox

      This solution does not work because I want to actually display values in each
      comboBox. I tried the following code and each item still remained
      highlighted.

      .cboBox1.Items. AddRange(New Object() {"A", "B", "C"})
      .cboBox2.Items. AddRange(New Object() {"A", "B", "C"})
      .cboBox6.Items. AddRange(New Object() {"A", "B", "C"})
      .cboBox1.Select edIndex = -1
      .cboBox2.Select edIndex = -1
      .cboBox6.Select edIndex = -1
      .cboBox1.Text = "A"
      .cboBox2.Text = "B"
      .cboBox6.Text = "C"



      "Some Guy" wrote:
      [color=blue]
      > Set them to -1
      > .cboBox1.Select edIndex = -1
      > .cboBox2.Select edIndex = -1
      > .cboBox6.Select edIndex = -1
      >[/color]

      Comment

      • Some Guy

        #4
        Re: Selected text in a ComboBox

        It works

        ComboBox1.Selec tedText = "A"
        ComboBox2.Selec tedText = "B"
        ComboBox3.Selec tedText = "C"
        ComboBox1.Selec tedIndex = -1
        ComboBox2.Selec tedIndex = -1
        ComboBox3.Selec tedIndex = -1






        "genojoe" <genojoe@discus sions.microsoft .com> wrote in message
        news:24E38826-1540-483A-BF2E-BA56BE1447CE@mi crosoft.com...[color=blue]
        > This solution does not work because I want to actually display values in
        > each
        > comboBox. I tried the following code and each item still remained
        > highlighted.
        >
        > .cboBox1.Items. AddRange(New Object() {"A", "B", "C"})
        > .cboBox2.Items. AddRange(New Object() {"A", "B", "C"})
        > .cboBox6.Items. AddRange(New Object() {"A", "B", "C"})
        > .cboBox1.Select edIndex = -1
        > .cboBox2.Select edIndex = -1
        > .cboBox6.Select edIndex = -1
        > .cboBox1.Text = "A"
        > .cboBox2.Text = "B"
        > .cboBox6.Text = "C"
        >
        >
        >
        > "Some Guy" wrote:
        >[color=green]
        >> Set them to -1
        >> .cboBox1.Select edIndex = -1
        >> .cboBox2.Select edIndex = -1
        >> .cboBox6.Select edIndex = -1
        >>[/color]
        >[/color]


        Comment

        • genojoe

          #5
          Re: Selected text in a ComboBox

          You are correct. I finally went to a new project and could duplicate your
          result. In my actual application, however, I still ended up with all
          combobox text highlighted. Below is my actual abridged code that, frankly,
          does not make sense and seems to indicate some kind of bug in .NET

          FYI: In the actual application, I had the following line of code associated
          with each combobox in the parent form:

          Me.cboBox2.Anch or = CType(((System. Windows.Forms.A nchorStyles.Top Or
          System.Windows. Forms.AnchorSty les.Left) _
          Or System.Windows. Forms.AnchorSty les.Right),
          System.Windows. Forms.AnchorSty les)

          I then opened the form with:
          Dim mfrmCommon As frmCommon = New frmCommon
          With mfrmCommon
          ............... ........Set text, etc. for various controls on form
          .ShowDialog()
          End With

          When opening frmCommon this way, every combobox was highlighted. I added
          the following line of code in the With statement for each combobox and the
          problem went away.

          .cboBox1.Anchor = CType((System.W indows.Forms.An chorStyles.Top
          Or System.Windows. Forms.AnchorSty les.Left), System.Windows. Forms.AnchorSty les)

          I short, I changed the combobox anchor from top, left, right to top, left to
          solve the problem. Go figure.


          "Some Guy" wrote:

          Comment

          Working...