467,075 Members | 995 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

Combo boxes initially highlighted

I have five comboboxes each has a item listed populated by hand in the IDE.
Each has the text property bound to a text field in the database. When I
initially fill the dataset and display the page all of these combo boxes
display the correct data, but all of them are highlighted as if they have
focus.

If I click in on and then click another control the highlight goes away. I
have a tabbed interface and If I navigate to another tab and back the
highlights are gone from all of the combo boxes.

How can I get them to initially display the data not highlighted?

Gary
Nov 21 '05 #1
  • viewed: 4898
Share:
14 Replies
Gary,

They are highlighted because that the 0 index is the selected one initially.

Set the selectedindex to -1 of each after loading and that goes away.

I hope this helps?

Cor
Nov 21 '05 #2
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
They are highlighted because that the 0 index is the selected one
initially.


Nevertheless, the comboboxes should not remain highlighted if they don't
have the focus.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
But all five of them remain highlighted. I tried the suggestion Cor left
but that had no effect.

I'm at a lost to explain how five combo boxes could all appear to have
focus at the same time.

Gary
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eJ**************@TK2MSFTNGP14.phx.gbl...
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
They are highlighted because that the 0 index is the selected one
initially.


Nevertheless, the comboboxes should not remain highlighted if they don't
have the focus.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Thanks, I tried that with no effect. This is very strange.

Gary

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Gary,

They are highlighted because that the 0 index is the selected one initially.
Set the selectedindex to -1 of each after loading and that goes away.

I hope this helps?

Cor

Nov 21 '05 #5
Gary,

Can you explain this sentence a little more, I overreaded it focused on the
focus.
I have five comboboxes each has a item listed populated by hand in the IDE.
Each has the text property bound to a text field in the database.


When you have databind it to the database, than it should show the current
item in the database and not an item that you loaded. And is than a little
bit strange.

I have tried to simulate what you did, however cannot get your behaviour.

Cor
Nov 21 '05 #6
Gary,

Can you show how you bind them, just one is enough.

I ask you this because you are so definitly talking about binding while the
normal way is to set the datasource of the combobox to the table of the
dataset and than tell which displaymember (datafield) will be used.

When you do that and you use the index_change event from the comboboxes.
Than do you have to protect that it is firing in advance. The most used
method is a startupswitch (bool), which is set to true as soon as the
datasource and members of the comboboxes are set.

I hope this helps?

Cor
Nov 21 '05 #7
I only use a datasource and displaymember (and usually valuemember) if I
want the drop down list portion of the combo box to be populated from a
database, but that is not what I am doing in this instance at all so all
three of those are set to nothing.

As I have said, my drop down list is populated by way of the Items
collection in the VB.NET IDE. I just typed in the four possible allowed
values there. Under the databindings properties I have the text property
bound to my field in the database.

Here is the generated code from the form designer:

'cmbPartner
Me.cmbPartner.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or
System.Windows.Forms.AnchorStyles.Left) _Or
System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.cmbPartner.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.datasetLocScenario, "Scenario_to_Location.PartnerType"))
Me.cmbPartner.ItemHeight = 13
Me.cmbPartner.Items.AddRange(New Object() {"", "Customer", "Supplier",
"Lead"})
Me.cmbPartner.Location = New System.Drawing.Point(568, 302)
Me.cmbPartner.Name = "cmbPartner"
Me.cmbPartner.Size = New System.Drawing.Size(176, 21)
Me.cmbPartner.TabIndex = 52

Gary

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u0*************@TK2MSFTNGP09.phx.gbl...
Gary,

Can you show how you bind them, just one is enough.

I ask you this because you are so definitly talking about binding while the normal way is to set the datasource of the combobox to the table of the
dataset and than tell which displaymember (datafield) will be used.

When you do that and you use the index_change event from the comboboxes.
Than do you have to protect that it is firing in advance. The most used
method is a startupswitch (bool), which is set to true as soon as the
datasource and members of the comboboxes are set.

I hope this helps?

Cor

Nov 21 '05 #8
Gary,

It was the code I expected (exactly as you described) however what would it
do in your opinion.
(And therefore I asked you to show it, because I could misunderstand you).

The databinding is to set the text from the dataadapter field to the same
text in the combobox as is the currentposition in the datatable to what it
is binded. However that dataset has now in my opinion no way to change its
position.

What is your purpose now?

Cor
Nov 21 '05 #9
I'm sorry Cor, but I just do not follow this second paragraph at all.

The code works as I expect it to. That is, the form displays with data from
my dataset. I can pick an item from the drop down list and the dataset is
updated.

Changing position of the dataset is outside the scope of this question. My
application uses a tree to pick what record is displayed on this form. When
I close the form the dataset changes (if any) are written back to the
database.
The user picks another item from the tree and a new instance of my form pops
up.

None of this is the issue, though. The issue remains, with this code all
the combo boxes are initially highlighted.

Gary

"Cor Ligthert" <no************@planet.nl> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Gary,

It was the code I expected (exactly as you described) however what would it do in your opinion.
(And therefore I asked you to show it, because I could misunderstand you).

The databinding is to set the text from the dataadapter field to the same
text in the combobox as is the currentposition in the datatable to what it
is binded. However that dataset has now in my opinion no way to change its
position.

What is your purpose now?

Cor

Nov 21 '05 #10
Well I think I finally found it. But I don't understand it! <big ol' grin>

I did a test where I removed the items collection from one of the
comboboxes. Then it still correctly displayed the data from my dataset, the
list portion of the combo box was empty as expected, but the text was not
highlighted!

I wondered if what I was seeing was an indication that the control was
telling me when it found a match between the dataset data shown and an item
in the list portion. To test that further, I replaced the items collection
but removed ONE item. Displaying various records in my database proved my
theory. Any time the data displayed had a matching item in the collection
the text was highlighted. Any time there was no match the text was not
highlighted.

I then realized that since I wanted to limit the user to pick ONLY from an
item in the collection, I should change the DropDownStyle property from
DropDown to DropDownList. When I did this and added the removed item back
to the collection, none of the displayed records produced a highlighted text
result!

This certainly is strange behavior though, I didn't try it here, but I am
pretty sure from other projects that if I had bound the datasource to a
table and set the displaymember, that a displayed record with a match in the
dataset bound item collection would NOT have resulted in highlighted text
even with the DropDownStyle set to the default DropDown value.

Gary
"Cor Ligthert" <no************@planet.nl> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Gary,

It was the code I expected (exactly as you described) however what would it do in your opinion.
(And therefore I asked you to show it, because I could misunderstand you).

The databinding is to set the text from the dataadapter field to the same
text in the combobox as is the currentposition in the datatable to what it
is binded. However that dataset has now in my opinion no way to change its
position.

What is your purpose now?

Cor

Nov 21 '05 #11
Gary,

I have fight myself often with the combobox. In my (and I have seen in this
newsgroup not only my) opinion is it the most buggy control there is.

The expirience that you describe now, did I have as well. However I am still
not see how you bind it (It is not interesting to describe it, when you
found your solution it is OK).

Maybe is there something happening I never thought about, although I have
expirienced a lot with that combobox in the same way as you are doing now.

I am glad you are finding the solution.

Cor
Nov 21 '05 #12
I do want to continue the discussion, even if I did find a solution, because
at some point it might be necessary to allow the user to enter an item not
in the item collection. In that case the DropDownStyle would HAVE to be
DropDown not DropDownList. And then I'm back to highlighted entries.

Here is the binding:

Me.cmbPartner.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.datasetLocScenario, "Scenario_to_Location.PartnerType"))

Nothing fancy. Very straight forward.

I am not sure though if maybe the combobox is supposed to highlight the text
IF there is a match between the text portion and an item in the item
collection (the list portion of the combo). That may just be the intended
behavior. I say this because I do have another combo box on this same page,
it does have it's DataSource pointing to a dataset and uses the
DisplayMemeber and ValueMember. That one has a databinding from the forms
main dataset to the SelectedValue property. It has the same behavior when
its DropDownStyle is set to DropDown. The text is initially highlighted.
Setting that property to DropDownList and the highlight is gone.

Gary

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u4**************@TK2MSFTNGP15.phx.gbl...
Gary,

I have fight myself often with the combobox. In my (and I have seen in this newsgroup not only my) opinion is it the most buggy control there is.

The expirience that you describe now, did I have as well. However I am still not see how you bind it (It is not interesting to describe it, when you
found your solution it is OK).

Maybe is there something happening I never thought about, although I have
expirienced a lot with that combobox in the same way as you are doing now.

I am glad you are finding the solution.

Cor

Nov 21 '05 #13
Gary,

What I did to test your behaviour was making a small test program.

Maybe can you look at that and change what is in your situation not the same
and try to get the behaviour you have, than we know both what it is.
(I did not change the style of the combobox yet in this)

\\\needs only 3 comboboxes on a form
Private Sub Form1_Load(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Me.ComboBox1.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
Me.ComboBox2.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
Me.ComboBox3.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
dt.Columns.Add("Num")
For i As Integer = 0 To 5
dt.Rows.Add(dt.NewRow())
dt.Rows(i)(0) = (i + 1).ToString
Next
BindingContext(dt).Position = 1
ComboBox1.DataBindings.Add("Text", dt, "Num")
ComboBox2.DataBindings.Add("Text", dt, "Num")
ComboBox3.DataBindings.Add("Text", dt, "Num")
End Sub
///
Nov 21 '05 #14
I loaded your code and of course it doesn't have the same behavior as mine.
<grin> or maybe it should be <sigh>

Now the question I have to answer myself is "what's different?".

I'll try to do that over the next few days but since the app is now working
with the other dropdown style and deadlines are looming close, it will have
to take a lower priority.

Thanks for you help. This is truly baffling, frustrating and highly
interesting all at the same time!

Gary

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Gary,

What I did to test your behaviour was making a small test program.

Maybe can you look at that and change what is in your situation not the same and try to get the behaviour you have, than we know both what it is.
(I did not change the style of the combobox yet in this)

\\\needs only 3 comboboxes on a form
Private Sub Form1_Load(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Me.ComboBox1.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
Me.ComboBox2.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
Me.ComboBox3.Items.AddRange(New Object() _
{"1", "2", "3", "4", "5", "6"})
dt.Columns.Add("Num")
For i As Integer = 0 To 5
dt.Rows.Add(dt.NewRow())
dt.Rows(i)(0) = (i + 1).ToString
Next
BindingContext(dt).Position = 1
ComboBox1.DataBindings.Add("Text", dt, "Num")
ComboBox2.DataBindings.Add("Text", dt, "Num")
ComboBox3.DataBindings.Add("Text", dt, "Num")
End Sub
///

Nov 21 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Hank | last post: by
4 posts views Thread by Don Sealer | last post: by
1 post views Thread by Jack | last post: by
1 post views Thread by John Kreps | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.