Jump to content

dbGrid refresh


gbh100

Recommended Posts

I have an application where I open a window to edit information contained in a grid. After the line has been edited in the other window I refresh the table in the host grid and the changes are shown. this works fine in the Windows App but when I run it in a browser (IE9) the change doesn't show until I go to edit the same line again. Is there something I have to do to refresh the web version of the grid? Is this a bug or just my being lame?

Link to comment
Share on other sites

  • Administrators

Hello:

 

I have yet to use DBGrid.Refresh after any refresh of base dataset (table, query or stored proc).

 

At the same time the dataset.edit does not work on DBGrid.

 

There will be always differences between WEB and VCL. This is nature of web programming.

 

You can't edit a grid unless you set focus on Grid's active cell. For example, consider you have three DBEdits and one DBGrid on Form and you set DataSet to Edit mode, where focus should go? Edit1, Edit2 or DBGrid?

Link to comment
Share on other sites

The edit is not actually done on the grid, but rather a modal window is used to perform the edit. After the modal window edit is completed I use a dataset.refresh to try and get the updated information. It works fine in the Win32 application. The dataset is actually a query and I also tried closing the query and re-querying which also works fine in the Win32 app but not in the Web version. Is there a way to force the web screen to update? I'm sure the underlying dataset has the new information in both cases but the web screen is unaware of the changes.

Link to comment
Share on other sites

  • Administrators

The edit is not actually done on the grid, but rather a modal window is used to perform the edit. After the modal window edit is completed I use a dataset.refresh to try and get the updated information. It works fine in the Win32 application. The dataset is actually a query and I also tried closing the query and re-querying which also works fine in the Win32 app but not in the Web version. Is there a way to force the web screen to update? I'm sure the underlying dataset has the new information in both cases but the web screen is unaware of the changes.

 

In this scenario grid must be refreshed. Can you send a simple test case?

Link to comment
Share on other sites

Here is the code:

 

procedure TfrmEditTeam.grdBattersDblClick(Sender: TObject);

begin

frmPlayerEdit(True, qryBatters_ID.AsInteger).ShowModal;

qryBatters_.Refresh;

end;

 

As you can see there is not much to see here. The frmPlayerEdit is an editing form with its own instance of the table being edited. The table is refreshed after the change and does get the updated information as the VCL version works. I have tried closing and opening the table and that has the same results. When I double click another or even the same row to initiate another edit I see the underlying grid update before the new edit window is drawn. It seems that the mechanism notifying the web client of a change is not aware of any changes to notify the client about.

Link to comment
Share on other sites

As you can see there is not much to see here. The frmPlayerEdit is an editing form with its own instance of the table being edited. The table is refreshed after the change and does get the updated information as the VCL version works.

There is actually much to see here. Your table is refreshed before the change, not after, because ShowModal doesn't block execution in unigui.

You must use callback events to execute some code after window is closed.

But you don't need manual refresh here at all:

1. Your modal Form should have UniDbEdit components attached to some Form.DataSource for editing and UniButton(s) with some ModalResult. Assign your dataset to Form.DataSource before calling ShowModal.

2. Call dataset.Edit or dataset.Insert before Form.ShowModal

3. Call Form.ShowModal

3. In Form.OnClose event check for ModalResult and either do dataset.Post or dataset.Cancel, unidbgrid will be updated automatically, no need to call a manual refresh.

 

You need this extra datasource on modal form if your dataset is located on another form. If your dataset/datasource is in datamodule, you can attach uniedits directly without the need of extra datasource and passing of dataset.

Link to comment
Share on other sites

There will be always differences between WEB and VCL. This is nature of web programming.

 

You can't edit a grid unless you set focus on Grid's active cell. For example, consider you have three DBEdits and one DBGrid on Form and you set DataSet to Edit mode, where focus should go? Edit1, Edit2 or DBGrid?

 

to the Active Control??? :(

 

In this scenario if the DBGrid is ActiveControl it must stay there. When I click with mouse in the cell it become to edit state and cursor is ready for input in the appropiate cell. So in this case let change the call to Edit:

 

DBGrid.Append or DBGrid.Edit this will do:

 

1- Call the Edit for DataSource.DataSet

2- Stay DBGrid as ActiveControl

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...