Ticket Q485293
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

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

Composite Key Model Not Selectable On Listview

created 12 years ago

Hi,
I have a question about usage of tables that have composite key. Suppose that we have an xpo generated model in xaf application. This model is generated by using the metadata of a database table that has composite key. In an XAF application, the listview that list this kind of model does not have checkboxes to select on listview. So, we cannot use selectable records in ViewControllers. How can we solve this problem?

Thanks.

Answers approved by DevExpress Support

created 12 years ago (modified 7 years ago)

Hello Alperen,
17.1.4+
You can use the StructTypeConverter<T>  for struct key properties to enable some built-in DevExpress.Web.ASPxGridView functions(e.g., inplace editing and the selection column).
Older versions
An object can be selected in the ASPxGridView if its key property can be serialized to the String type. To fulfill this requirement when the composite key is used, apply a custom TypeConverter to it. Here is an example:

C#
[TypeConverter(typeof(MyKeyConverter))] public struct MyKey { private string _Property1; [Persistent] public string Property1 { get { return _Property1; } set { _Property1 = value; } } private string _Property2; [Persistent] public string Property2 { get { return _Property2; } set { _Property2 = value; } } } public class MyKeyConverter : TypeConverter { public override Boolean CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(String)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is String) { string[] values = ((String)value).Split(';'); if (values.Length == 2) { return new MyKey() { Property1 = values[0], Property2 = values[1] }; } } return base.ConvertFrom(context, culture, value); } public override Object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value, Type destinationType) { if (destinationType == typeof(String)) { MyKey key = (MyKey)value; return String.Format("{0};{1}", key.Property1, key.Property2); } return base.ConvertTo(context, culture, value, destinationType); } }

    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.