By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Selected text in a ComboBox

P: n/a
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.SelectedIndex = 0
.cboBox2.SelectedIndex = 1
.cboBox6.SelectedIndex = 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.SelectionLength = 0
.cboBox6.Select(0, 0)
.cboBox1.Focus()

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

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Set them to -1
.cboBox1.SelectedIndex = -1
.cboBox2.SelectedIndex = -1
.cboBox6.SelectedIndex = -1

"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
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.SelectedIndex = 0
.cboBox2.SelectedIndex = 1
.cboBox6.SelectedIndex = 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.SelectionLength = 0
.cboBox6.Select(0, 0)
.cboBox1.Focus()

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

Nov 21 '05 #2

P: n/a
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.SelectedIndex = -1
.cboBox2.SelectedIndex = -1
.cboBox6.SelectedIndex = -1
.cboBox1.Text = "A"
.cboBox2.Text = "B"
.cboBox6.Text = "C"

"Some Guy" wrote:
Set them to -1
.cboBox1.SelectedIndex = -1
.cboBox2.SelectedIndex = -1
.cboBox6.SelectedIndex = -1


Nov 21 '05 #3

P: n/a
It works

ComboBox1.SelectedText = "A"
ComboBox2.SelectedText = "B"
ComboBox3.SelectedText = "C"
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = -1
ComboBox3.SelectedIndex = -1


"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
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.SelectedIndex = -1
.cboBox2.SelectedIndex = -1
.cboBox6.SelectedIndex = -1
.cboBox1.Text = "A"
.cboBox2.Text = "B"
.cboBox6.Text = "C"

"Some Guy" wrote:
Set them to -1
.cboBox1.SelectedIndex = -1
.cboBox2.SelectedIndex = -1
.cboBox6.SelectedIndex = -1

Nov 21 '05 #4

P: n/a
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.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)

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.Windows.Forms.AnchorStyles.Top
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)

I short, I changed the combobox anchor from top, left, right to top, left to
solve the problem. Go figure.
"Some Guy" wrote:

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.