C#: ComboBox Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a comboBox set to also be editable. If I have code that is
something like:

cmbBox.Text = "Hello";
MessageBox.Show(cmbBox.Text);

The MessageBox will display just an empty string. I cannot figure this out.
The text "Hello" will be displayed in the combobox but it doesn't seem to
store the text. If I edit the box at runtime then it does store it correctly.

This is very important. It is the last bug I need to fix in my Project to
graduate, in which I am working with the Rolla Police Department. Thanks.
 
Hi Tony,

I am unable to reproduce your bug, and for me the MessageBox will display "Hello".

Can you show us a small but complete code sample demonstrating the problem?
 
Let me give more information first. As to getting a small code demonstration
that might be difficult as this is a very large program.

The ComboBox is bound to a DataTable which is what I believe is causing the
problem. I want the user to be able to select from the list or type in their
own copy and this part works.

When the program reads from the Database and does something similar to
cmbBox.Text = temp.ToString() where temp is a value from the database which
is not a member of the list, then it doesn't seem to accept it. If the user
say then retypes the same thing it will.

Hopefully that clears it up a little.
 
I was able to get it to work. It seems that when the comboBox is bound to a
datasource, cmbBox.Text="text" will only work if "text" is one of the options
from the datasource. It will put "text" in the box, but doesn't save it in
the Text Property.

So what I had to do was add a new row to the DataView which was bound to the
ComboBox which had the same text that I read from the database. This was only
temporary and wasn't saved back to the database.

Thanks for the help.

Tony
 
Thank you for reporting the solution :)


I was able to get it to work. It seems that when the comboBox is bound to a
datasource, cmbBox.Text="text" will only work if "text" is one of the options
from the datasource. It will put "text" in the box, but doesn't save it in
the Text Property.

So what I had to do was add a new row to the DataView which was bound to the
ComboBox which had the same text that I read from the database. This was only
temporary and wasn't saved back to the database.

Thanks for the help.

Tony
 
Back
Top