Description:
I'm trying to bind the XtraGrid to a table that has a recursive relationship, eg. Employee-ReportsTo. I would like the grid to behave in a similar manner to your XtraTreeList - to build a tree according to the relations in the table. Can this be done?
Answer:
The XtraTreeList is best used for displaying self-referenced tables. However, you can also use the XtraGrid for this task.
You will need to create a relation for your data table (use the DataSet Schema editor) and bind the grid to the table. It will automatically allow you to expand master rows to see child records.
In this scenario, the main grid view displays all the table rows. You will need to filter the grid's data source to show only "root" records. Here is the code to bind the grid to the filtered data:
C#DataView dv = new DataView(dataset11.Products);
dv.RowFilter = "([ParentID] Is NULL)";
gridControl1.DataSource = dv;
Visual BasicDim dv As DataView = New DataView(dataset11.Products)
dv.RowFilter = "([ParentID] Is NULL)"
gridControl1.DataSource = dv
You may wish to set up detail views to have the same layout as the main grid view. Please handle the MasterRowGetLevelDefaultView event of the main grid view to implement this:
C#private void gridView1_MasterRowGetLevelDefaultView(object sender,
DevExpress.XtraGrid.Views.Grid.MasterRowGetLevelDefaultViewEventArgs e) {
GridView view = new GridView(gridControl1);
view.Assign(gridControl1.MainView, true);
view.OptionsView.ShowGroupPanel = false;
e.DefaultView = view;
}
Visual BasicImports DevExpress.XtraGrid.Views.Grid
Private Sub gridView1_MasterRowGetLevelDefaultView(ByVal sender As Object, ByVal e As MasterRowGetLevelDefaultViewEventArgs) Handles gridView1.MasterRowGetLevelDefaultView
Dim view As GridView = New GridView(gridControl1)
view.Assign(gridControl1.MainView, True)
view.OptionsView.ShowGroupPanel = False
e.DefaultView = view
End Sub
This only works if there is only one detail if there are 2 or more it really messes up
Hello,
Let's discuss the case with several relations in the How to display a self-referenced data table via master and detail grid views with several relations thread.
Hi
How to remove columns header from sub levels and making sure sub levels columns are aligned with the grid header like the XtraTreeView.
I cannot use XTreeView since i have hundreds off hours of coding around a gridview.
I see that you've asked a similar question in the GridView - How to hide the detail view's tab header, group panel and column headers thread. I've posted my answer there.
Please don't duplicate your questions since it increases the response time and complicates processing of your tickets.