0

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.

4

1 回答 1

4

浏览Master-Detail Overview并检查该Data Sources部分以了解您可以实施以提供数据源的具体方式。如果要实现主细节,则必须使用IRelationList接口或主细节为对象定义关系:使用事件

检查基于Master-Detail 关系中的Pattern 和 Clone Views部分创建的示例

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;
        }
    }

使用的类:

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; }
}

其中 Foos 是主行,并且对于包含 Bars 列表的每个 Foo 显示一个“加号”按钮来显示“Bar”子表?

如果没有成功,请尝试按照上述方法实施,然后按照主 - 详细信息部分的数据规范部分进行操作。

如果您想在单击详细信息展开按钮时获取 Bars,则 crateMaster-Detail: Using Events它几乎是实现您拥有的任何数据对象的自定义方式。

于 2013-05-23T07:44:00.560 回答