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…