KB Article A273
Visible to All Users

How to Make the Events of my Detail View Objects Work as Expected

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 Basic
Private 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 Basic
Private 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?

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.