StrataFrame Forum

Problem with Combobox

http://forum.strataframe.net/Topic11181.aspx

By Luiz Carneiro Lima - 8/28/2007

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?

By StrataFrame Team - 8/29/2007

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.