Ticket T110803
Visible to All Users

How to get an actual data row for a DetailView

created 11 years ago

Hello,

I have few master detail views on my grid.  I am using

((ColumnView)gridControl1.FocusedView).GetDataSourceRowIndex(currentRowHandle);

to get the selected row in the datasource, as suggested by few posts by other members.  Please see the attached code and the relevant method is

gridView3_FocusedRowChanged().

The problem is that it gets wrong datasource index - Please look at the attached image for more info.  It counts the row handle relative to every child view.  So the row handle of 1 could appear in more than one child views, hence not unique.

Is there any way to get the correct data row from the datasource, which actually does correspond to the actual row in the datasource?

Kind Regards

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
Each detail view has a unique data source. That is why the GetDataSourcRowIndex returns the same value for different detail views. I recommend that you review the “Identifying Rows and Cards” help topic for additional information.
I believe the best way to retrieve correct data row it to use this approach:

C#
ColumnView detailView = (ColumnView)gridView1.GetDetailView(gridView1.FocusedRowHandle, 0); int detailRowHandle = detailView.FocusedRowHandle; DataRow row = detailView.GetDataRow(detailRowHandle);

Please try this solution and let me know your results.

    Show previous comments (3)
    DevExpress Support Team 11 years ago

      Hello,
      This behavior is caused by the fact that a focused row handle is not changed in this case, but a focused detail view is changed. I recommend that you review the "Detail Pattern and Clone Views" help topic to learn more about this functionality.
      To resolve this issue, handle the GridControl.FocusedViewChanged property, for example, like this:

      C#
      private void gridControl1_FocusedViewChanged(object sender, DevExpress.XtraGrid.ViewFocusEventArgs e) { if (e.View.Name == gridView3.Name) (e.View as GridView).FocusedRowHandle = int.MinValue; }

      Please try this solution and let me know your results.

        Hello Andrey,
        Handling FocusedViewChanged in combination with FocusedRowChanged works great - Thanks for your assistance!
        (May be in future, dev express changes this behaviour, which would eliminate the need of using FocusedViewChanged for this)
        Kind Regards

        DevExpress Support Team 11 years ago

          You're welcome, Sophie.
          We do not have plans to change the current behavior since it is logical. Each DetailGrid has its own row numbering starting with zero and its own datasource. Thus, the FocusedRowChanged event is raised only when a focused row handle is changed.
          Please feel free to contact us in case of any difficulty. We are happy to help you at any time.

          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.