Description:
How to Make the Events of my Detail View Objects Work as Expected
Answer:
Using the Master-Detail feature of the XtraGrid, you may use different event handlers of your detail view object. A common mistake in such situations is to refer to your view objects created at design-time directly. For example, the following code will never work as expected:
C#private void detailView_EndGrouping(object sender, System.EventArgs e) {
detailView.ExpandAllGroups();
}
Visual BasicPrivate Sub DetailView_EndGrouping(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailView.EndGrouping
DetailView.ExpandAllGroups()
End Sub
The cause of this problem is that the grid Control always uses COPIES of the original view objects when creating detailed views. In this case you are interacting with the original view object not the copy currently being used to display the data. As a result, manipulation of its methods and properties will seem to have no effect.
The best way to resolve this is to utilize the sender parameter passed to the event which is the actual view copy currently being used. Just typecast it to the required View type and call the necessary method as illustrated in these code samples:
C#private void detailView_EndGrouping(object sender, System.EventArgs e) {
if(sender is DevExpress.XtraGrid.Views.Grid.GridView)
(sender as DevExpress.XtraGrid.Views.Grid.GridView).ExpandAllGroups();
}
Visual BasicPrivate Sub DetailView_EndGrouping(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailView.EndGrouping
If TypeOf sender Is DevExpress.XtraGrid.Views.Grid.GridView Then
CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).ExpandAllGroups()
End If
End Sub
See also:
Pattern and Clone Views topic in the XtraGrid help
What can cause the properties, methods, and events of a detail grid view to fail?