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;
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 :
or
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.