Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringGrid RowColChange event... 1

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,

I'm new to Delphi (converted from vb)

Is there any way to catch up when users changing row/col in a TStringGrid control (that is, when current cell changes)? Something just like C1.TrueDBGrid.RowColChange?

Thanks for reply,

Rej Cloutier
 

Did you look in the help file for events and properties of TStringGrid?

Take a look at OnSelectCell and OnTopLeftChanged.

Then look at the Row and Col properties.

Can you be more specific about what you are trying to do?

 
Hi,

I just want to update/insert records (that is, to launch an SQL statement) when users modified/entered all info on a specific row.

There is 2 buttons below my grid: save and undo. Saving info OnSelectCell has the result to make the undo button useless. That's why I need to implement something like

procedure OnRowChange(AOldRow: Integer, ANewRow: Integer);

 
Updating and inserting records in a database:

Use a dbGrid in combination with a dbNavigator. The dbNavigator has the buttons:
Edit, Post, Cancel, Next, Last etc...

Steven
 
You should be able to use OnSelectCell along with a variable to hold the "previous" row.

Assuming you initialize the TStringGrid with the cursor in Cells[1,1] (assuming one fixed row and one fixed column), at the same time initialize the variable (e.g. AOldRow) to the value 1.

Then process OnSelectCell at which time you have AOldRow(your variable) and ARow (from the parameter list) to examine and handle however you need to. As the last step, set AOldRow to ARow.

The code might look something like this (OnRowChange is your routine):
Code:
var
  AOldRow:integer;  // Static variable
procedure MyForm.MyGridSelectCell(Sender: TObject;
        ACol, ARow: Integer; var CanSelect: Boolean);
begin
  if AOldRow <> ARow then
    OnRowChange(AOldRow,ARow);
  AOldRow := ARow
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top