Can I populate a DevExpress LookupEdit using an enum?


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

I would like to use enums to populate a LookupEdit column in a DevExpress grid. I've worked my way to the BuildDataTableFromEnum method and that seemed to hold the clue but I can't work out how to use it. Before spending a lot of time on this I thought I had better ask if it is even possible. If it is, do you have a code snippet I could use?

Cheers, Peter

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


For anyone who is interested the following seems to work ok when binding a DevExpress lookup edit to an internal enum. It involves creating a BO for each enum which, of course, gives great portability.


1. Make a generic view to use when creating an enum BO:

SELECT '' AS Description, '' AS Value


2. Created BO using the above view. In this example we are creating a BO for our DeviceType enums.


3. Created Business Binding Source mapped to the BO.


4. Add this code to the enum's BO's ParentFormLoading event:

   Private Sub boEnumDeviceType_ParentFormLoading() Handles Me.ParentFormLoading
        Dim dt As New Data.DataTable
        dt = MicroFour.StrataFrame.Tools.Common.BuildDataTableFromEnum(GetType(TMS_Test_01.TMSEnums.DeviceType))
        Me.CopyDataFrom(dt, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)
        dt = Nothing
    End Sub

5. Created a LookUpEdit control in DevExpress using the BBS as the datasource and mapped Description as the display member and Value as the value member.


And that was it. The combo box shows the enum descriptions and the value saved to the database is enum's integer value.

So, all we need to do is create BO's for each of our enums that are visible on the UI and use them just as we would a table.

Cheers, Peter

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