combobox datasource dropdown problem

N

Norm Katz

When you use a bound combobox and you set its dropdown style to "dropdown"
that allows you to enter text in the edit box. But if you enter anything
other than a value in the current bound items collection, the .text property
does not update. Furthermore, you can't easily trap an event to examine the
new value if your program assigns it programmatically as opposed to someone
typing it in and tabbing away from it. That is, TextChanged does not fire
when you programmatically assign the combobox .text property.

Even after you do the assignment, when your code has a chance to read the
combobox, it turns out that the .text value is still set to the last valid
string assigned (by binding or another assignment) EVEN THOUGH THE VISIBLE
TEXT SHOWS SOMETHING DIFFERENT. I call this a bug, but obviously, the
underlying combobox code is written to store the old value returned by
getting the .text property and not exposing the visible text.

I'm assuming this is a well-known problem. I've verified that it does not
occur if you populate a comobox manually, i.e., don't bind it.

First, does it even make sense to allow someone to enter a value (or let the
program assign a value) that is not found in the bound data or is it assumed
that the bound combobox style should be set to "dropdown list?"

Next, I saw an example where the programmer adds the newly entered value
into the list in the TextChanged event, but this won't work for me because:
a) This event doesn't fire on programmatic assignment of the .text property
b) The combobox is bound to a dataset, so items.add fails with an error
saying that this is not permitted when the control's datasource is set.

Can someone suggest a straightforward solution to capturing the assignment
of the .text property and retrieving this property (via adding it to the
items collection or some other means)?

Thanks a bunch!
Norm
 
H

Herfried K. Wagner [MVP]

* "Norm Katz said:
When you use a bound combobox and you set its dropdown style to "dropdown"
that allows you to enter text in the edit box. But if you enter anything
other than a value in the current bound items collection, the .text property
does not update. Furthermore, you can't easily trap an event to examine the
new value if your program assigns it programmatically as opposed to someone
typing it in and tabbing away from it. That is, TextChanged does not fire
when you programmatically assign the combobox .text property.

Windows Forms Data Binding group:

<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top