Ticket Q394159
Visible to All Users

How to get a parent record/row handle in the master/detail grid

created 13 years ago

I have a grid configured as a master/detail grid. When a user sets focus to a detail record, I would like to also set the parent grid record pointer to the master record. Which property will give me the parent's row index so I can select it?
 private void detailGrid_IsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            GridControl detail = sender as GridControl;
            if (detail.IsKeyboardFocusWithin)
            {
                // want to select the parent record of the master table when any detail record is selected
                // but how to get the row handle of the master record??
                // grid.View.FocusedRowHandle = ??
            }
        }

Show previous comments (1)
DevExpress Support Team 13 years ago

    Hi Shawn,
    The data context of the grid placed within the detail template is a RowData class object that describes the corresponding master row. Therefore you can obtain both the parent row handle and the currently focused row of the master grid as follows:

    C#
    private void detail_IsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e) { GridControl detail = sender as GridControl; if (detail.IsKeyboardFocusWithin) { RowData data = (RowData)detail.DataContext; int parentRowHandle = data.RowHandle.Value; int masterFocusedRowHandle = data.View.FocusedRowHandle; } }

    I have attached a sample project that illustrates this approach in action. Please try this solution and provide us with your feedback on whether or not it suits your needs.
    Thanks,
    Dmitry

    ?
    Unknown 13 years ago

      Great, that worked perfectly… thanks!

      DevExpress Support Team 13 years ago

        You are welcome!

        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.