Ticket Q587278
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?

XAF Web - ListViews of objects with compound key doesn't show SelectionColumns

created 11 years ago

Hi,

I'm working on an application that maps a Legacy DB. Many tables have compund keys.
The ListViews of objects with compound key doesn't show SelectionColumns, instead the listview shows the Delete Button.

How can I force the selection box to appear?

Attached is a screenshot of the listview.
Thanks,
Analia

Here is the sample code:

public struct SectorDepositoKey
{
[NoForeignKey]
[Persistent("STTDEI_DEPOSI")]
[Size(15)]
public Deposito Deposito { get; set; }

[Persistent("STTDEI_SECTOR")]
[Size(15)]
public string Sector { get; set; }

public SectorDepositoKey(Deposito _Deposito, string _CodSector)
: this()
{
Deposito = _Deposito;
Sector = _CodSector;

}
}

[DefaultClassOptions]
[OptimisticLocking(false)]
[DefaultProperty("Codigo")]
[Persistent("STTDEI")]
// Specify more UI options using a declarative approach (http://documentation.devexpress.com/#Xaf/CustomDocument2701).
public class SectorDeposito : XPBaseObject
{ // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (http://documentation.devexpress.com/#Xaf/CustomDocument3146).
public SectorDeposito(Session session)
: base(session)
{
}

[Key, Persistent, Browsable(false), VisibleInDetailView(false), VisibleInListView(false), VisibleInLookupListView(false)]
public SectorDepositoKey Key { get; set; }

[PersistentAlias("Key.Deposito")]
public Deposito Deposito
{
get { return (Deposito)(EvaluateAlias("Deposito")); }
set { Key = new SectorDepositoKey(value, Codigo); } // If you need to edit the key parts.
}

[PersistentAlias("Key.Sector")]

public string Codigo
{
get { return Convert.ToString(EvaluateAlias("Codigo")); }
set { Key = new SectorDepositoKey(Deposito, value); } // If you need to edit the key parts.
}

private string _Descripcion;
[VisibleInLookupListView(true)]
[Size(60), Persistent("STTDEI_DESCRP")]
public string Descripcion
{
get
{
return _Descripcion;
}
set
{
SetPropertyValue("Descripcion", ref _Descripcion, value);
}
}

}
}

[DefaultClassOptions]
[OptimisticLocking(false)]
[DefaultProperty("Codigo")]
[Persistent("STTDEH")]
// Specify more UI options using a declarative approach (http://documentation.devexpress.com/#Xaf/CustomDocument2701).
public class Deposito : XPBaseObject
{ // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (http://documentation.devexpress.com/#Xaf/CustomDocument3146).
public Deposito(Session session)
: base(session)
{
}

private string _Codigo;
[Key, Size(15), Persistent("STTDEH_DEPOSI"), VisibleInListView(true)]
public string Codigo
{
get
{
return _Codigo;
}
set
{
SetPropertyValue("Codigo", ref _Codigo, value);
}
}

private string _Descripcion;
[VisibleInLookupListView(true)]
[Size(60), Persistent("STTDEH_DESCRP")]
public string Descripcion
{
get
{
return _Descripcion;
}
set
{
SetPropertyValue("Descripcion", ref _Descripcion, value);
}
}

}

Answers approved by DevExpress Support

created 11 years ago (modified 7 years ago)

Hello Analia Veronica,
To make objects with the compound key selectable in the Web ListView, you are required to apply a TypeConverter to the key structure. Please refer to similar tickets:
Composite Key Model Not Selectable On Listview
Error to display a detail view with a CompoundKeyStruct and TypeConverter.

Starting with the 17.1.4 version, 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).
Also, I can see that there is a reference to a persistent object in your key structure. Since TypeConverter cannot load persistent objects, change your structure to store only the object's key. In your persistent class, you can obtain the related persistent object based on this key using the Session.GetObjectByKey method. Here is an example:

C#
[TypeConverter(typeof(SectorDepositoKeyTypeConverter))] public struct SectorDepositoKey { [Persistent("STTDEI_DEPOSI")] [Size(15)] public string Deposito { get; set; } [Persistent("STTDEI_SECTOR")] [Size(15)] public string Sector { get; set; } public SectorDepositoKey(string _Deposito, string _CodSector) : this() { Deposito = _Deposito; Sector = _CodSector; } } [DefaultClassOptions] [OptimisticLocking(false)] [DefaultProperty("Codigo")] [Persistent("STTDEI")] public class SectorDeposito : XPBaseObject { public SectorDeposito(Session session) : base(session) { } [Key, Persistent, Browsable(false), VisibleInDetailView(false), VisibleInListView(false), VisibleInLookupListView(false)] public SectorDepositoKey Key { get; set; } [PersistentAlias("Key.Deposito")] public Deposito Deposito { get { return Session.GetObjectByKey<Deposito>(Key.Deposito); } set { Key = new SectorDepositoKey(value == null ? String.Empty : value.Codigo , Codigo); } } [PersistentAlias("Key.Sector")] public string Codigo { get { return Convert.ToString(EvaluateAlias("Codigo")); } set { Key = new SectorDepositoKey(Deposito == null ? String.Empty : Deposito.Codigo, value); } } private string _Descripcion; [VisibleInLookupListView(true)] [Size(60), Persistent("STTDEI_DESCRP")] public string Descripcion { get { return _Descripcion; } set { SetPropertyValue("Descripcion", ref _Descripcion, value); } } } public class SectorDepositoKeyTypeConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) return true; if (sourceType == typeof(DevExpress.Xpo.Helpers.IdList)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string[] v = ((string)value).Split(new char[] { ',' }); return new SectorDepositoKey { Deposito = v[0], Sector = v[1] }; } if (value is DevExpress.Xpo.Helpers.IdList) { DevExpress.Xpo.Helpers.IdList v = (DevExpress.Xpo.Helpers.IdList)value; return new SectorDepositoKey { Deposito = (string)v[0], Sector = (string)v[1] }; } return base.ConvertFrom(context, culture, value); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) return ((SectorDepositoKey)value).Deposito + "," + ((SectorDepositoKey)value).Sector; return base.ConvertTo(context, culture, value, destinationType); } }

Please let me know if there is any issue with this implementation.

    Show previous comments (9)
    A A
    Analia Veronica Urbano Gonzalez 11 years ago

      Hi Anatol,
      yes ServerMode was enabled. I turned it off, and now it works!
      But I like to work with ServerMode on, so I'll wait for your comments on your research of this problem.
      Thanks,
      Analia

      Anatol (DevExpress) 11 years ago

        I apologize for the delayed response. I should have noticed this initially - the ASPxGridView does not support composite keys in Server Mode - see Database Server Mode Limitations. So, you will have to turn the server mode off in such views.

        A A
        Analia Veronica Urbano Gonzalez 11 years ago

          Ok, Thanks Anatol.

          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.