Ticket T433447
Visible to All Users

Refreshing "current" record or entire view

created 8 years ago

Hello

Actually I have two questions:

  1. I have a dbTableView binded to a dataset. How the properties of underlying DataController should be set to see changes made to records after refreshing the dataset calling DataController.RefreshExternalData . At present when I modifycertain records outside the dataset (ie executing 'UPDATE' statements), dataset gets refreshed but view displays old values.

  2. The dataset I use has ability to refresh "current" record instead to entire resultset. I've tried to add popup menu to allow user execute 'refresh' procedure. I'd like to use

<View>.DataController.DoUpdateRecord(<View>.DataController.FocusedRecordIndex);

but when the menu popups the FocusedRecordIndex gets value -1 and then its useless for this purpose. How I can pass "current" record index to DoUpdateRecord method.

Thanks
Marcin

Show previous comments (1)

    Let's skip item 1 and try to focus on item 2.
    If DoUpdateRecord is not recommended method, what is the alternative. Beside of that how can I obtain a RecordIndex of the row where popup menu was invoiked? (i.e in OnPopup event). This also would allow me to control visibilty of menu items basing on column values. At present FocusedRecordIndex returns -1.

    Thanks
    Marcin

    DevExpress Support Team 8 years ago

      As I mentioned above, the recommended approach is to use the Smart Refresh mode and update data by using DataController methods.
      As for using the view's PopupMenu, right clicking a certain record should focus this record under default conditions (see the attached project). It is difficult to say why this does not happen in your project without examining it. If you wish to know what record is under the mouse cursor when the menu's OnPopup event occurs, you can use our HitTest technology. The following draft solution should help you accomplish this task:

      Delphi
      procedure TForm1.PopupMenu1Popup(Sender: TObject); var APoint: TPoint; AHitTest: TcxCustomGridHitTest; begin APoint := cxGrid1DBTableView1.Site.ScreenToClient(GetMouseCursorPos); AHitTest := cxGrid1DBTableView1.GetHitTest(APoint); if (AHitTest <> nil) and (AHitTest.HitTestCode = htCell) and (TcxGridRecordCellHitTest(AHitTest).GridRecord is TcxGridDataRow) then Caption := IntToStr(TcxGridRecordCellHitTest(AHitTest).GridRecord.RecordIndex); end;

        Thank you for the tips.
        I thought it is not relevant, but does it make any difference that mentioned view is Detail view?
        I had some problems with above code, so added a button with foillowing code:

        ShowMessage(IntToStr(viewZTK.DataController.FocusedRecordIndex) + #13#10 + IntToStr(viewLT.DataController.FocusedRecordIndex));

        Where viewZTK is detail and viewLT is master.

        No matter what record in viewZTK is highlighted,  viewZTK.DataController.FocusedRecordIndex always returns -1.

        Any clues?
        Thanks
        Marcin

        Answers approved by DevExpress Support

        created 8 years ago (modified 8 years ago)

        I see. Thank you for your clarification. From what I gather, the viewZTK object is a detail pattern view. This view does not contain records. However, it is used to create detail clones (real detail views that contain master view rows' detail data). Please review the "Pattern and Clone Views" help topic for additional information. Thus, I suggest that you try using the following code line to get the focused view's focused record index:

        Delphi
        AIndex := cxGrid1.FocusedView.DataController.FocusedRecordIndex;
          Show previous comments (2)

            RefreshExternalData doesn't work since it calls Dataset.Refresh and nothing more.
            Closing and reopening is the last thing I'd like to do since all necessary data is on the client side. But I found UpdateItems method and

            Delphi
            cxGrid1.FocusedView.DataController.UpdateItems(False)

            works.

            The last question would be: how can I determine if "Focused" view is Master (viewLT) or Detail (viewZTK)? Simply checking like below?

            Delphi
            if (cxGrid1.FocusedView is viewLT) then

            Thanks
            Marcin

            DevExpress Support Team 8 years ago

              You can use the cxGrid1.FocusedView.IsDetail property to check if a focused view is a detail view. The cxGrid1.FocusedView.PatternGridView property should help you find a pattern view of the focused detail view.

                That would be all.
                Thanks for help - time to read some help topics

                Have a nice weekend
                Marcin

                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.