Problem with Combobox


Author
Message
Luiz Carneiro Lima
Luiz Carneiro Lima
StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)StrataFrame Beginner (25 reputation)
Group: Forum Members
Posts: 25, Visits: 87
Hi,

I have a combobox that it is populado thus:

---------

cbTipo.Items.Add(new DictionaryEntry("Pessoa F¡sica", "F"));

cbTipo.Items.Add(new DictionaryEntry("Pessoa Jur¡dica", "J"));

cbTipo.Items.Add(new DictionaryEntry("Prospect", "P"));

cbTipo.Items.Add(new DictionaryEntry("Internacional", "I"));

---------

This textbox is bind with a field string of the Business Object that in the data base keeps value “F”, “J”, “P”, “I”.

When I select an option of the Combobox gives an error of cast (Unable you cast object of type “System.DBNull” to type “System.String”.)

I already configured in the Customize wizard:

Return Alternate on Null/Set Null on Alternate (value type) = string. Empty

You can help me?

Attachments
erro.jpg (74 views, 221.00 KB)
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The problem is most likely that your combo box is not setting the SelectedValue properly.  Check the SelectedValue property of the ComboBox and see what the value is.  Also, you might post the stack trace from that exception dialog that pops up, it might help.

Also, if the SelectedValue is wrong, then you might need to use the DataSource property of the ComboBox.  Instead of adding the items directly, create a DictionaryEntry[] and set it as the data source:

DictionaryEntry[] dataSource = new DictionaryEntry[] {
    new DictionaryEntry("Pessoa F¡sica", "F"),
    new DictionaryEntry("Pessoa Jur¡dica", "J"),
    new DictionaryEntry("Prospect", "P"),
    new DictionaryEntry("Internacional", "I") };
cbTipo.DataSource = dataSource;
cbTipo.DisplayMember = "Key";
cbTipo.ValueMember = "Value";

That should get you fixed.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search