473,503 Members | 10,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
14 5315
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2364
by: Andrew | last post by:
Hello, I am trying to create a chart whose underlying query is linked to 2 combo boxes on the same form. I want to pass the values from the combo boxes into the chart query to allow the chart...
1
2118
by: Hank | last post by:
On various forms I have combo boxes with preloaded selections. I click the down arrow to display the choices. On some of the boxes, if I type the first letter of the selection (Lets say "C") then...
4
1532
by: Don Sealer | last post by:
I have a form that is based on a table called CVA Defects Table. Three of the fields in the table and form are Oil line defects, Gas line defects, and Sub assembly defects. These fields use...
1
1470
by: Jack | last post by:
Hello, On a form, I have a tab control with two tab pages. On one tab page, I have about seven group boxes which I hide and make visible when buttons are clicked on the tab page. No problems...
0
2914
by: Jeremy Wallace | last post by:
Folks, Here's a write-up I did for our developer wiki. I don't know if the whole rest of the world has already figured out how to do this, but I hadn't ever seen it implemented, and had spent a...
0
1583
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
3
1084
by: mvenkatesan | last post by:
hi in my project is search site within combox boxes(3) it related to eachother initially select one combo and it fire the next combo and last fire the listout the items. initially i put the...
1
1617
by: John Kreps | last post by:
I've tried to get combo boxes to work with Access 2007 for days now without success. What I can't get to work is the autocomplete. I've got three simple tables and one form with two controls....
11
3039
by: jgoodnight | last post by:
Hi, I have a form with three combo boxes: Area, Sub-Area, and Factor. I've set up the Sub-Area combo box to list only those areas that are part of the selected area. I've set up the Factor combo...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.