How to populate comboboxes with options such as M/F for Male/Female (longer lists of course)


How to populate comboboxes with options such as M/F for Male/Female...
Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Alex,

The question is, what is the best way to I populate comboxes using Strataframe in those cases?

You can use any data type you need as it relates to binding.  In this example you may not want to use an enum, as these will always be stored as an integer.  You will want to create your data source manually:

Dim myTable As New DataTable("")
Dim newRow As DataRow

'-- Create the columns
myTable.Columns.Add("display",GetType(String))
myTable.Columns.Add("value", GetType(String))

'-- Then populate your table
newRow = MyTable.NewRow()
newRow.Items("display") = "Apple"
newRow.Items("value") = "A"
MyTable.Rows.Add(newRow)

'-- Once populated, set the combo
MyCombo.DisplayMember = "display"
MyCombo.ValueMember = "value"
MyCombo.DataSource = MyTable

You will bind to the combo just as you would for an enum, the difference is that the SelectedValue or value member of the combo will bind to the [value] field in the table which you have defined as a string, which in return will allow you to bind to a character field, which ultimately gets saved back to the database as character.  Hope this helps. Smile

AlexSosa
AlexSosa
StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)
Group: Forum Members
Posts: 35, Visits: 138
Thank you Peter.

Alex

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

We store the enum (integer) value so the above wouldn't work for you.

I've never had to do the same with an option group so I can't help with that one.

Cheers, Peter

AlexSosa
AlexSosa
StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)
Group: Forum Members
Posts: 35, Visits: 138
Thank you Peter,

I am still a newbie so I can' t tell from reading your code if your technique stores a number or a character in the table?  I'd like to store a character in the table.

Similar problem with optionbuttons.  How do you handle that one?

Thanks,

Alex

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You might also use an attribute on each enum value to indicate an alternate value to use. See this post:



http://forum.strataframe.net/FindPost5781.aspx
Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi ALex,

You can still use an enum but show a single letter (or a full name) to the user. Our enum BO's just have the following code:

    Private Sub boenBatchTypes_ParentFormLoading() Handles Me.ParentFormLoading
        Dim ColDesc As String = "Description"
        Dim dt As New Data.DataTable

        dt = MicroFour.StrataFrame.Tools.Common.BuildDataTableFromEnum(GetType(UtilEnums.clsEnum.BatchTypes))

        ' Localise Batch names
        For i As Integer = 0 To dt.Rows.Count - 1
            dt.Rows.Item(i).Item(ColDesc) = UtilLocalisation.clsLocalise.Localise(dt.Rows.Item(i).Item(ColDesc).ToString)
        Next

        dt.DefaultView.Sort = ColDesc
        Me.CopyDataFrom(dt.DefaultView.ToTable, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

        dt = Nothing
    End Sub

In this example:

.BuildDataTableFromEnum - standard SF function to extract our "batch name" enums and creates a data table

UtilLocalisation.. - is our own function to localise the enum description.

Me.CopyDataFrom - standard SF sub to load the populate the BO.

Easy as and works a treat.


Cheers, Peter

AlexSosa
AlexSosa
StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)StrataFrame Beginner (43 reputation)
Group: Forum Members
Posts: 35, Visits: 138
In .NET it is usual (recommended?) to use integers and ennumerations to identify options.  Nevertheless, I still like to use single letters such as M/F for Male/Female etc and I can get away with it since I don't deal in multilingual apps.

The question is, what is the best way to I populate comboxes using Strataframe in those cases?

TIA,

Alex

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