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

Deleting row in string grid 1

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
Ok, I feel like a dunce because I can't figure this out. I can clear the whole grid by getting the number of rows and just doing a clear on all of them in a for loop...but I can't figure out how to just clear the row the person has slected. I'm not sure how to determine which row they have selected either.

Any help on this, probably stupid, problem is greatly appreciated:)
 
For the first part, you could use something like this:
Code:
procedure StringGridDeleteRow( AStringGrid:TStringGrid; ARow:integer );
var
  nRow:integer;
begin
  with AStringGrid do
    begin
      for nRow := ARow to RowCount - 2 do
        Rows[nRow].Assign(Rows[nRow+1]);
      Rows[RowCount-1].Clear;
      RowCount := RowCount - 1
    end;
end;
For the second part, see the help file for the Row and Col properties. For example:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  StringGridDeleteRow(StringGrid1, StringGrid1.Row);
end;

 
That worked perfectly, thanks a million!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top