I want some thing like Master-Detail pattern in XtraGridcontrol.
Eg:
+Master
-Chid1
-Child2
Please see that attached screen shot. I want to display the records like that.
Thanks
Satheesh M
We have closed this ticket because another page addresses its subject:
Grid List Editors - How do I show both master and detail records in the same grid control (aka master-detail)WinForms - How to enable Master-Detail mode (a detail grid view is displayed within a master row of the same the grid control)
Answers
Hi Satheesh,
You can add a new view controller, implementing it as follows:
C#using System;
using DevExpress.ExpressApp;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.ExpressApp.Win.Editors;
namespace WinSolution.Module.Win {
public class MasterDetailViewController : ViewController<ListView> {
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null) {
GridControl grid = gridListEditor.Grid;
GridView view = gridListEditor.GridView;
view.OptionsPrint.PrintDetails = true;
view.OptionsDetail.ShowDetailTabs = true;
view.OptionsView.ShowDetailButtons = true;
view.OptionsDetail.EnableMasterViewMode = true;
view.MasterRowExpanded += view_MasterRowExpanded;
}
}
private void view_MasterRowExpanded(object sender, CustomMasterRowEventArgs e) {
GridView masterView = sender as GridView;
GridView detailView = masterView.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
detailView.BeginUpdate();
detailView.OptionsDetail.EnableMasterViewMode = false;
detailView.OptionsBehavior.Editable = false;
foreach (GridColumn col in detailView.Columns) {
if (col.FieldName.Contains("!")) {
col.Visible = false;
col.OptionsColumn.ShowInCustomizationForm = false;
}
}
detailView.EndUpdate();
}
}
}
Visual BasicImports System
Imports DevExpress.ExpressApp
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.ExpressApp.Win.Editors
Namespace WinSolution.Module.Win
Public Class MasterDetailViewController
Inherits ViewController(Of ListView)
Protected Overrides Sub OnViewControlsCreated()
MyBase.OnViewControlsCreated()
Dim gridListEditor As GridListEditor = TryCast(View.Editor, GridListEditor)
If gridListEditor IsNot Nothing Then
Dim grid As GridControl = gridListEditor.Grid
Dim view As GridView = gridListEditor.GridView
view.OptionsPrint.PrintDetails = True
view.OptionsDetail.ShowDetailTabs = True
view.OptionsView.ShowDetailButtons = True
view.OptionsDetail.EnableMasterViewMode = True
AddHandler view.MasterRowExpanded, AddressOf view_MasterRowExpanded
End If
End Sub
Private Sub view_MasterRowExpanded(ByVal sender As Object, ByVal e As CustomMasterRowEventArgs)
Dim masterView As GridView = TryCast(sender, GridView)
Dim detailView As GridView = TryCast(masterView.GetDetailView(e.RowHandle, e.RelationIndex), GridView)
detailView.BeginUpdate()
detailView.OptionsDetail.EnableMasterViewMode = False
detailView.OptionsBehavior.Editable = False
For Each col As GridColumn In detailView.Columns
If col.FieldName.Contains("!") Then
col.Visible = False
col.OptionsColumn.ShowInCustomizationForm = False
End If
Next col
detailView.EndUpdate()
End Sub
End Class
End Namespace
My sample project is attached. Let me know if this meets your needs.
In addition, I suggest you track the following suggestion: ID AS12152 (ListEditors - Support showing both master and detail records in the same grid control).
Thanks
Dennis
P.S.
See also:
ID Q30147 (Show only one child tab within the grid control),
ID Q30148 (How can i suppress the tab header in the grid control),
ID Q30149 (How can i show my custom icon on child grid row header).
@sunay: This sample was created for an older XAF version, and there is no ObjectType property in the View class now. Use the ObjectTypeInfo property instead. As for the Master type, this demo class is declared in the example code and it seems that you forgot to reference it. Should you have any further difficulties, please create a separate ticket and attach your own sample that shows your current implementation.
Hi Dennis,
Can you please give us a solution on how to synchronize the master-detail view with an ListView template defined in the model?
As soon as the master row is expanded, I get all columns displayed like the object's view is not known by the system…
I do not understand why it is not built in, since xaf use WIN components… I have lost too much time already trying to use expand but can't make it work since I have an application Server architecture…
Please help
@Maxime: While I do not have a complete example, the eXpressApp Framework > Concepts > Application Model > Access the Application Model in Code article describes how to implement the XAF-related part of this task, e.g., access the localized column value. You can customize the detail GridView object (see the "detailView" variable in the code above) based on this information as per the XtraGrid documentation. As for the built-in GridListEditor support, our team will take your request into account, though I cannot promise any implementation time frame. Our GridListEditor (technically a wrapper over the GridControl) integrates just a subset of the grid control features with the XAF's Application Model and other standard XAF system modules with great capability for customization and extension. So if something is not available by default, you can always implement it yourself exactly as you would approach this without XAF.
BTW, have you evaluated the alternative solutions #1 and #2 from the How do I show both master and detail records in the same grid control? thread?
Finally, you mentioned that you tried to use the eXpand Framework solution for this task. Have you contacted their support forum (http://www.expandframework.com/forum/index.html) about your difficulties? To my understanding, this feature is standalone and it should work regardless of the client or server security configuration. Please submit a separate ticket if you want to discuss this situation further.