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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Value from String Grid 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a string grid that is filled as follows:

Jurnum LastName FirstName CheckedIn
132 Smith Jane No
167 Doe John No
231 Williams Stuart No

When the user doubleclicks on a row, I'd like to check a TStringList to see if the value of JurNum is in the list, if it's not there add the number and if it is there then remove the number. However, I can't figure out which row I'm on! I know that I need the first column, but how can I tell what row has been selected?

Code:
procedure TfrmRecordHours.sgRecordHoursDblClick(Sender: TObject);
begin
  if CheckInList.IndexOf(Value of Column 0 and selected Row) = -1 then
  begin
    CheckInList.Add(Value of Column 0 and selected Row);
  end
  else
    CheckInList.Delete(CheckInList.IndexOf(Value of Column 0 and selected Row));
  FillRecordHOursGrid(qryRecordHours);
end;

Thanks,

leslie
 

See the Selection property of TStringGrid. (And the goRangeSelect Option.)

 
I guess I'm just being dense, but I can't figure out how to take the 'SELECTION' example and transform it into something I can use!!

Here's all I could find on selection:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  myRect: TGridRect;
begin
  myRect.Left := 3;
  myRect.Top := 1;
  myRect.Right := 2;
  myRect.Bottom := 4;
  DrawGrid1.Selection := myRect;
end;

 
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := IntToStr(StringGrid1.Selection.Top);
end;
You should probably also turn off the goRangeSelect option so that only one row can be selected at a time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top