Ticket Q473102
Visible to All Users
Duplicate

server mode & db control synchronization

created 12 years ago

We have used cxGrid1ServerModeTableView
(VCL) in our project .but our biggest problem is that we cannot synchronize
cxGrid with DB controls. We don’t want to use Inplace Editor.for editing
records we should use DB controls of Delphi.
What is the best way of
binding and synchronizing cxGrid with DB controls?
When will you support
this capability in cxGrid1ServerModeTableView ?

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello,
Thank you for your question. We have no plans to implement such synchronization at the level of our controls as we already have the in-place editing capability. You can use the following approach to implement the synchronization yourself:

  1. Link your DB editors to a table used to display data in the Server Mode View;
  2. Handle the <ServerModeView>.OnFocusedRecordChanged event and locate the current record by the key value:
Delphi
procedure TForm1.cxGrid1ServerModeTableView1FocusedRecordChanged( Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); var ID: Variant; begin ID := Sender.DataController.GetValue(AFocusedRecord.RecordIndex, 0); if ADOTable1.Active then ADOTable1.Locate(dxServerModeADODataSource1.KeyFieldNames, ID, []); end;
  1. Handle the DataSet's OnAfterPost event, and update the Server Mode View's DataController and DataSource data there:
Delphi
type TdxServerModeADODataSourceAccess = class(TdxServerModeADODataSource); procedure TForm1.ADOTable1AfterPost(DataSet: TDataSet); begin TdxServerModeADODataSourceAccess(dxServerModeADODataSource1).Cache.SoftReset; cxGrid1ServerModeTableView1.DataController.Refresh; end;

P.S.: We plan to slightly simplify this algorithm with future versions of our controls (see the Server Mode - Improve data interoperability between server mode data sources and standalone data-aware editors bound to the same database ticket).

    Comments (2)
      1. This Is not good Solution for me because it needs one time cxGrid in server Mode send request to server & Other Time my Dataset send request to server Then two time send request required
      2. i Patched devexpress grid :: DoExecuteCommand & FetchRows to use internal devX grid dataset
        why Do not grant user to use internal cxGrid Dataset ?
        or better way : use Sql Dataset as Base for Dataset ?
        function TdxServerModeADQueryDataSource.FetchRows(AWhere: TdxServerModeCriteria; ASortInfo: TdxServerModeSortInfoDescriptors; ATopRecords: Integer): TdxServerModeRowList;
        begin
           Result := TdxServerModeRowList.Create;
          if ExecuteCommand(@FADataSet, FieldDescriptors, AWhere, ASortInfo, nil, ATopRecords, 0) then
          try
            while not FADataSet.Eof do
            begin
              Result.Add(dxCreateServerModeRow(FADataSet.Fields));
              FADataSet.Next;
            end;
          finally
            //ADataSet.Free;
            //ADataSet.First;
          end;
        end;
        procedure TdxServerModeDataSourceADHelper.DoExecuteCommand(AResultSet: PDataSet; const ACommand: string; AParams: TParams;
          AParamCheck: Boolean);
        var
          I: Integer;
        begin
          Query:=nil; //changed
          query:=TADQuery.Create(nil);
          try
            query.Close;
            query.Connection := TADConnection(Connection);
            if (AParams <> nil) and (AParams.Count > 0) then
            begin
              query.SQL.Text := ACommand;
              for I := 0 to AParams.Count - 1 do
                query.Params[I].Value := AParams[I].Value;
              query.Open();
              AResultSet^ :=query;
            end
            else
            begin
              query.Open(ACommand);
              AResultSet^ :=query;
            end;
            // Query.Close; don't close
          finally
            // FreeAndNil(Query); don't free
          end;
        end;
        This Patch have any problem ?
      DevExpress Support Team 12 years ago

        Hello,
        I doubt that this code can help you implement a reliable solution for your task. In Server Mode our grid gets data from the server portion by portion. So the FADataSet DataSet will contain only the latest requested portion. Moreover, it is not always correct to use the TDataSet.Open method you are using in DoExecuteCommand. It is necessary to use the TDataSet.ExecSQL method instead in certain cases (e.g., when deleting a record).
        I suggest you use features we implemented in the context of the Server Mode - Improve data interoperability between server mode data sources and standalone data-aware editors bound to the same database ticket to synchronize DB editors with Server Mode.

        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.