Question

I have an IList which I'm passing as a parameter to a Dev Express 10.2 GridControl Datasource. Each "Foo" may have an IList or not. How should I have to do, to make a Master-Detail grid, where the Foos are the master rows, and for each Foo that contains a list of Bars display a "plus" button for displaying "Bar" subtable?

I'm using nHibernate, so, I cannot use datatables/datasets to make this work (as we can see at DevExpress online docs)

I realized that GridControl have a boolean property called EnableMasterViewMode, but I could not make this thing to work. Where I'm doing it wrong?

Here I'm using WinForms.

Thank you in advance.

Was it helpful?

Solution

Go through Master-Detail Overview and also check the Data Sources section for the specific way you can implement to provide data source. If you want to implement master detail then you must define relations for Objects either using the IRelationList Interface or Master-Detail: Using Events

Check the sample created on the basis of Pattern and Clone Views section in the Master-Detail Relationships

public partial class MasterDetails : Form
    {
        GridControl grid;
        GridView view;
        GridView detailView;
        GridLevelNode detailNode;        
        public MasterDetails()
        {
            InitializeComponent();            
            InitializeGrid();
            InitializeAndAddColumnsToViews();
            InitializeAndBindDataSource();
        }

        private void InitializeGrid()
        {
            grid = new GridControl();
            view = new GridView(grid);
            detailView = new GridView(grid);
            detailNode = grid.LevelTree.Nodes.Add("SuppliersProducts", detailView);
            grid.Dock = DockStyle.Fill;
            this.Controls.Add(grid);
        }
        private void InitializeAndAddColumnsToViews()
        {
            if (view != null && detailView != null)
            {
                view.Columns.AddField("CategoryID").VisibleIndex = 0;              

                detailView.Columns.AddField("ID").VisibleIndex = 0;
                detailView.Columns.AddField("Name").VisibleIndex = 1;
                detailView.Columns.AddField("Category").VisibleIndex = 2;
            }
        }

        private void InitializeAndBindDataSource()
        {
            List<BookDetail> bookDetails = new List<BookDetail>();

            BookDetail bookDetail = null;
            for (int j = 0; j < 5; j++)
            {
                bookDetail = new BookDetail { CategoryID = j + 1 };
                for (int i = 0; i < 5; i++)
                {
                    bookDetail.Books.Add(new Book
                    {
                        ID = 1,
                        Name = "Book - " + (i + 1),
                        Category = j + 1
                    });
                }
                bookDetails.Add(bookDetail); 
            }
            grid.DataSource = bookDetails;
        }
    }

Class that are used:

public class Category
{      
    public int ID { get; set; }
    public string Name { get; set; }

}
public class BookDetail
{
    private List<Book> books = new List<Book>();
    public int CategoryID { get; set; }        
    public List<Book> Books
    {
        get
        {
            return books;
        }
        set
        {
            books = value;
        }
    }
}
public class Book
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int Category { get; set; }
}

where the Foos are the master rows, and for each Foo that contains a list of Bars display a "plus" button for displaying "Bar" subtable?

try to implement as above approach if not get success then follow the data specification section of the Master - Detail Section.

If you want to fetch Bars when detail expand button click then crate Master-Detail: Using Events it is almost custom way to implement whatever data objects you have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top