Can I populate a DevExpress LookupEdit using an enum?


Author
Message
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,

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

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
This will require the use of an embedded control which we do not have a wrapper for.  However, you can use the BuildDataTableFromEnum static (shared) method in the MicroFour.StrataFrame.Tools.Common namespace to create the data table that can then be used as a data source within the LookupEdit control.  For us to provide the native SF Enum population within the embedded control would require use to re-write some of the DevExpress type editors which just is not feasible.  The good news is that you can at least get the final result you are looking for. Smile
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,

Finally got around to doing this. I can create a data table ok and it has two columns headed Description and Value. The problem is that each column contains the enumation description (Dev0, Dev1 etc) but no enumeration value (0,1,3 etc).

My code the create the tables is:

Dim dt As New Data.DataTable

dt = MicroFour.StrataFrame.Tools.Common.BuildDataTableFromEnum(GetType(TMS_Test_01.TMSEnums.DeviceType))

 

My code to create the enumeration is:

Public Enum DeviceType As Integer

Dev0 = 0

Dev1 = 1

Dev2 = 2

Dev3 = 3

End Enum

What elso do I need to do?

Cheers, Peter

 


StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
When you create a DataTable from that tools method, the Value column of the DataTable will contain the actual enumeration value, not the integer tied to the enum value.
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,

Ok then. When I first looked at this issue that was the only method I could identify that could create an 'enum table'. Does SF have another method that will return the enum integer in the value column?

Cheers, Peter

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I don't think we have one that will just get the integer value for the enum.  We originally had all of the method return a DataTable with the value column populated with an integer, but we discovered that you couldn't bind to a strong-typed property that had been typed as an enum, but you can bind an enum populated combo box to an integer-typed property, so we changed the methods to populate the value column with the actual enum value.  This all happened in version 1.1 or 1.2, I'm not sure. 

If you want to be able to populate a column with the integer value, you can use the CreateDataTableFromEnum method and add an extra column, say "ValueInt", to the table, cycle through the rows, and set the integer value.  Then you'll just have to change the ValueMember of the control to "ValueInt", not "value".

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,


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