Ticket Q573903
Visible to All Users

Master Details: why there is no need to implement the IRelationList?

created 11 years ago

I tried to implement the IRelation to get Master Details while I noticed that only a public IList Property is enough to allow the Master Details mode.
Why? So far I did not see any part of the documentation mentioning such thing.

C#
public class Data { public Data() { this.C = "3"; this.D = "4"; } public String C { get; set; } public String D { get; set; } } public class Record : IListSource { public Record() { Random random = new Random(); this.Data = new BindingList<Data>(); for (Int32 i = 0; i < random.Next(10, 20); i++) { this.Data.Add(new Data()); } } public BindingList<Data> Data { get; set; } public String A { get; set; } public String B { get; set; } #region IListSource Members Boolean IListSource.ContainsListCollection { get { return this.Data is IList; } } IList IListSource.GetList() { return this.Data; } #endregion } public class ListSource : IListSource { public ListSource() { this.Records = new BindingList<Record>(); Random random = new Random(); for (Int32 i = 0; i < random.Next(10, 20); i++) { Record record = new Record(); record.A = random.Next(0, 42).ToString(); record.B = random.Next(42, 100).ToString(); this.Records.Add(record); } } protected BindingList<Record> Records { get; set; } #region IListSource Members Boolean IListSource.ContainsListCollection { get { return this.Records is IList; } } System.Collections.IList IListSource.GetList() { return this.Records; } #endregion }

Also I noticed than if I implement the IRelationList to use a protected IList, it does not work. Could you tell me where is the note about the required modifier to trigger the Master Details mode?
[EDIT]
FormMain.cs:

C#
public partial class FormMain : XtraForm { public FormMain() { this.InitializeComponent(); (this.gridControl.MainView as BaseView).DataController.AllowIEnumerableDetails = true; var dataSource = new IRelationListStuff.DataSource.DataSource(); this.gridControl.DataSource = dataSource; } }

DataSource.cs:

C#
public class DataSource : IEnumerable, IRelationList //IListSource { public DataSource() { this.BindingListDataLevel1 = new BindingList<DataLevel1>(); Random random = new Random(); for (Int32 i = 0; i < random.Next(2, 8); i++) { DataLevel1 dataLevel1 = new DataLevel1("A" + i, "B" + i); this.BindingListDataLevel1.Add(dataLevel1); } } protected BindingList<DataLevel1> BindingListDataLevel1 { get; set; } //Boolean IListSource.ContainsListCollection //{ // // yeah yeah I know... // get { return this.BindingListDataLevel1 is IList; } //} //System.Collections.IList IListSource.GetList() //{ // return this.BindingListDataLevel1; //} IEnumerator IEnumerable.GetEnumerator() { return this.BindingListDataLevel1.GetEnumerator(); } IList IRelationList.GetDetailList(int index, int relationIndex) { throw new NotImplementedException(); } string IRelationList.GetRelationName(int index, int relationIndex) { throw new NotImplementedException(); } bool IRelationList.IsMasterRowEmpty(int index, int relationIndex) { throw new NotImplementedException(); } int IRelationList.RelationCount { get { throw new NotImplementedException(); } } }

But I still get no exception while I this is a IEnumerable so this has no be considered by the grid or am I missing something else and in spite of using the option give here: https://documentation.devexpress.com/#WindowsForms/CustomDocument5496By default, properties of the IList and IEnumerable types are not recognized as collection properties. To treat them as collection properties, set theBaseView.DataController**.AllowIEnumerableDetails** option to true prior to binding a data source to the XtraGrid control.

Furthermore I noticed that there is no possibility for the IListSource to be used accordingly with IRelationList, your documentation only mentioned IList and IEnumerable so there is really no other workaround besides implementing IList and or IEnumerable (but does not work with my example above). Btw I tried with a basic IList implementation and it works…

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
Yes, it is sufficient to have a property of the IList type. See the Implement Master-Detail Relationships for Objects via Collection Properties help topic for more information. However, implementing the IRelationList interface for your data source object enables you to customize detail lists.
if I implement the IRelationList to use a protected IList, it does not work.
What list do you mean? There is no list property in the IRelationList interface. Would you please show us your IRelationList implementation?
We look forward to your reply.

    Show previous comments (1)
    Andrew Ser (DevExpress Support) 11 years ago

      Hi,
      The IRelationList.GetDetailList method enables you to return detail data for a specific relationship. Use the "index" (of the master row) and the "relationIndex" parameters to define the required list. Please see the Implement Master-Detail Relationships for Objects Using the IRelationList Interface help topic for a simple example of the IRelationList implementation.
      Should you have any difficulties, feel free to contact us at any time. We are always happy to help you.

        I updated the description of my post, the IEnumerable implementation does not allow the IRelationList to be considered by the grid. Is it an expected behavior? Where is it mentioned in the documentation that an IList is required?

        Yaroslav (DevExpress Support) 11 years ago

          Hi,
          Yes, this behavior is expected. You can't bind an IEnumerable in WinForms. The binding (and expecially the master-detail mode) requires random-access to the underlying data objects, but IEnumerable only allows you to get the current record and move it to the next one.
          Let us know if you have any other inquires.

          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.