Using StringGrid selectedText in different events, delphi

274 Views Asked by At

Im having a form with 2 buttons with 2 different events one sets an order to be ready the other to be declined. For my stringgrid i select records from database, and for the buttonClick events i create UPDATE query, with the advStringGrid.Selectedtext which value i put in the UPDATE query. But the problem is when i first click Ready button and after that i click Decline button,without closing form, then the string value remains only until first click. Perhaps theres an option to "immediately" or w/o closing form to get new value for advStringGrid.Selectedtext variable.

procedure TfTodoList.setRefusedbtnClick(Sender: TObject);
var
  i: Integer;
begin

  if (Sender = setRefusedbtn) and (State = 0) then
  begin

    qryExec.Sql.Text := 'Update KitchenOrderRow Set StatusID = 1' +
      ' Where   (OrderId in (Select OrderId from KitchenOrderHeader ' +
      ' Where Invoice = ' + IntToStr(Orders[X].Invoice) +
      ')) and (InvRowId = ' + IntToStr(Orders[X].InvRowId) + ')';

    advOrderGridClickCell(Sender, X, Y);
  end
  else if (State = 1) and (setRefusedbtn = Sender) then
  begin
    ProductName := advOrderGrid.SelectedText;
    qryExec.Sql.Text := 'Update KitchenOrderRow Set StatusID = 1' +
      ' where   productName = ''' + ProductName + ''' and StatusID = ' +
      IntToStr(qryStatusStatusID.asInteger) + '';
    State := 0;
    // fk_lib.logisse(nil, qryExec.Sql.Text);
  end;

  qryExec.ExecSQL;
  advOrderGrid.RemoveSelectedRows;
end;
1

There are 1 best solutions below

3
On

If you update some values in dataset which are used in DbGrid, you should refresh the dataset connected to DbCrid. Close/Open form do this. After execution of update query do this :

Grid.Datasorce.DataSet.Refresh;

or

Grid.Datasorce.DataSet.Close;
Grid.Datasorce.DataSet.Open;

Update:

If your grid is not connected directly with database through datalink(datasource) you can refresh it as execute the same procedure which is used to fill the grid with data.