Combobox


Author
Message
Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
I am getting the above error. I am maintaining chart information in a table and one of the columns is Chartype. In my form, I have the following code to display charttypes in the combobox. When I load the form or select a chart type, I get the error above. The column is not null and I have taken care of that in the BOMapper.

My combobox is bindingfield is configure to the ChartType column and businessobject is the BOChartsInventory1.

********************************************************************************

Dim chartTypes As String() = System.Enum.GetNames(GetType(ChartType))

Dim ct As String

For Each ct In chartTypes

Me.cboChartype.Items.Add(ct)

Next ct

Me.cboChartype.SelectedValue = Me.cboChartype.Items(Me.cboChartype.FindString(System.Enum.GetName(GetType(ChartType), Me.chrtsMain.AreaChart.LineDrawStyle), 0))

******************************************************************************************

Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Michael,

I would be having a look in the CurrentDataTable view when your code breaks on the error. I would imagine that you will, indeed, find a row with a null where you are not expecting a null to appear.

Cheers, Peter

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
I don't see the error anywhere in the post, so I'm going to assume that it's an InvalidCastException?  Well, most likely, the field you're binding to is an enum field, and the combo box is populated with strings, so that's not going to work.  Your best bet would be to use the PopulationType = Enumeration / PopulationEnumName = "enum name" on the combo box (they can be set through the property sheet).  If you have to populate it programmatically, then you'll want to use the MicroFour.StrataFrame.Tools.Common.BuildDataTableFromEnum() method and pass over the combo box you want to populate.  That method also takes advantage of the <EnumDisplayValueAttribute> that you can apply to the items in your enum (populates the combo box with what you place in the attribute, rather than the name of the enum value; easier on your users).
Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
Thanks

I put the error in the post subject line.  

"Conversion from type 'DBNull' to type 'String' is not valid."

Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
The Combobox will load the Enumeration fine. However, It will not load the value from my BO.Chartype column. When I select an item, the BO is not updated?

I set the SFCombo to the following; 

1. Set BindingField to MyChartypeField

2. Set the BO to MyBoChartsInventory1

3. Set the Populationtype to Enumeration

4. Set Populate EnunName to MyEnumChartype

5. PopulationOnFormLoad to FormLoad

What am I missing?

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
When binding a combo box to an enumeration, you have to have the bound field typed as that enumeration.  Meaning that if you have enum MyEnum, then the field on your BO should be customized so that it returns a MyEnum.  Then, the binding will work correctly.  So, if the column in the database is an integer type it will cast directly to the enum type, but if you want to store the data in a string column, you'll need to use custom code and put something like this:

Public Property MyField As MyEnum
    Get
        Return CType(Enum.Parse(GetType(MyEnum), CType(Me.CurrentRow("MyField"), String)), MyEnum)
    End Get
    Set(ByVal value As MyEnum)
        Me.CurrentRow("MyField") = value.ToString()
    End Set
End Property

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