Jump to content

How to Trap Enter in DBGrid and Refresh


carrera

Recommended Posts

Hi,

 I need to trap Enter Key in UniDBGrid for Refreshing Calculate Field

when user press enter in cell editor, cursor will focus to the next column and calculate field value will be changed (refresh)

 

i use  

TForm........UniDBGrid.OnKeyDown

   if Key = VK_RETURN then <-- it doesn't work, cannot trap enter key

       RefreshDataset;

 

 

 

Thank you

 

Environment

Delphi XE7

UniGui 0.99.80.1214

Link to comment
Share on other sites

I need to trap Enter Key in UniDBGrid for Refreshing Calculate Field

when user press enter in cell editor, cursor will focus to the next column and calculate field value will be changed (refresh)

 

i use  

TForm........UniDBGrid.OnKeyDown

   if Key = VK_RETURN then <-- it doesn't work, cannot trap enter key

       RefreshDataset;

 

Hi,

 

One of the possible solutions, may help, try

 

For now, you can use: UniDBGrid ... function edit(editor, context, eOpts)

 

1. UniDBGrid1 -> ClientEvents -> ExtEvents

function edit(editor, context, eOpts)
{
  function _post () {    
    ajaxRequest(editor.grid, '_post', []);
  }
  setTimeout(_post, 200);
}

2.

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
begin
  if EventName = '_post' then
  begin
    if (UniDBGrid1.DataSource.DataSet.State in [dsEdit]) then
      UniDBGrid1.DataSource.DataSet.Post;
  end;
end;

Best regards.

Link to comment
Share on other sites

  • 6 years later...

Hi,

I'm trying to implement this and it works good, but the event is also fired when pressing the tab button to go to the next field in line of the grid.

This makes that by tabbing to the next field the record is posted and the user needs to click the selected field again to edit it.

Is there a workaround for this?

Thx,

Dominique

Navigation.gif

Link to comment
Share on other sites

I've been able to solve this, but i have another problem.

I have attached a testcase.

I have a button to create a new record.

I do an append, fill in the default values, post the data and put the table in edit mode.

When entering data in the line

When creating a new line and entering data in the value of the field is reset when going to another field.

You can see it in the attached screenshot, the value of the second column is reset after entering the third field and going to the next field.

TestGridEdit.zip

Link to comment
Share on other sites

Can you try this approach?

1. function edit:

function edit(editor, context, eOpts)
{
  /*function _post () {    
    ajaxRequest(editor.grid, '_post', []);
  }
  setTimeout(_post, 200);*/
  return ajaxRequest(editor.grid, '_post', [], false).responseText == "true";
}

2. AjaxEvent:

procedure TMainForm.GridLinesAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_post' then
  begin
    if (GridLines.DataSource.DataSet.State in [dsInsert, dsEdit])
    then
    begin
      GridLines.DataSource.DataSet.Post;
      UniSession.SendResponse('true');
    end;    
  end;
end;

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...