Hello
Actually I have two questions:
-
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.
-
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
Hello Marcin,
In fact it should not be necessary to set special properties to make a grid view handle data set changes. In most cases a grid view receives notifications as well as other data-aware controls. Attached is a small sample project demonstrating how this update mechanism works. I mean, data set changes are reflected in view records. Would you please modify this project to demonstrate the problematic behavior?
The DoUpdateRecord method is undocumented and I do not think that it is a good idea to use it. Let me suggest you an alternative approach. Please take a look at the "TcxDBDataModeController.SmartRefresh" help topic. This SmartRefresh mode can help you avoid reloading of all data set records, but update only modified DataController records instead. I hope, this mode will help you accomplish your task.
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
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:
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