KB Article S173752
Visible to All Users

How can I use ASPxGridListEditor with XPO classes that have composite keys?

Scenario:
There is a database table with multiple key columns. The corresponding XPO class has a compound key property implemented through a structure, according to the How to create a persistent object for a database table with a compound key article. When a ListView of this class is shown, row-specific ASPxGridView functions, such as the inplace editing and the selection column, are disabled. This happens, because the ASPxGridView control cannot recognize the key value. See how to enable these functions below.

Solution:
In versions 17.1.4 and higher, decorate the key structure with the [TypeConverter(typeof(StructTypeConverter<YourKeyType>))] attribute. The StructTypeConverter<T> Class can serialize the specified structure to a string, which is required to support built-in ASPxGridView functions. See details and an example in the class description.
Note that this class cannot work with structure properties whose type is an XPO persistent class. If you have such a structure, either change it to use simple types, or implement one of the solutions described below.

In versions prior to 17.1.4, use one of the following solutions:

1. Create a custom TypeConverter for the key structure that can convert it to String and vice versa. See an example in the Composite Key Model Not Selectable On Listview ticket. If you have persistent objects in the key structure, modify this solution as described here: XAF Web - ListViews of objects with compound key doesn't show SelectionColumns.
2. Add an ASPxGridView control configured according to your requirements to your application, as described in the How to: Show a Custom Data-Bound Control in an XAF View (ASP.NET) topic. Take special note of the following members and their usage with compound or multi-field keys: ASPxGridView.KeyFieldName PropertyASPxGridView.FindVisibleIndexByKeyValue Method.
If you are an experienced XAF developer, you can implement an ASPxGridListEditor descendant and modify the way how it works with key values to support your data structure.

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.