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!

Delete a Row in StringGrid

Status
Not open for further replies.

pconrad

IS-IT--Management
Jul 12, 2002
28
US
How do I delete a row in a StringGrid?

Tnanks,

PC
 
The Cols property is an array of TStrings's. Roll through it, and delete the n'th element of each Col:
Code:
for i := 0 to mystringgrid.RowCount - 1 do
  if mystringgrid.Cols[i].Count >= n then
    mystringgrid.Cols[i].Delete(n);
TStrings's (or, as you'll declare 'em in your app, TStringList's) are very nifty and powerful. Look up TStringList in help. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
When I try that, I get the message "Cannot Insert or Delete rows from grid"
 
D'oh.
Where n is the row to delete:
Code:
for i := n to StringGrid1.RowCount - 2 do
  StringGrid1.Rows[i].CommaText := StringGrid1.Rows[i+1].CommaText;

StringGrid1.RowCount := StringGrid1.RowCount - 1;
CommaText is essentially the entire contents of the row. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top