Board index » cppbuilder » TStringGrid - how to delete a row?

TStringGrid - how to delete a row?


2004-01-03 12:21:59 AM
cppbuilder91
Help!
I want to delete a row from a TStringGrid. I tried
((TCustomGrid*)MyStringGrid)->DeleteRow(SelRow); where SelRow is an int.
It tells me that DeleteRow is not accessible.
Thanks for help
Hugh
 
 

Re:TStringGrid - how to delete a row?

"Hugh W Stewart" < XXXX@XXXXX.COM >wrote in message
Quote
I want to delete a row from a TStringGrid. I tried
((TCustomGrid*)MyStringGrid)->DeleteRow(SelRow);
where SelRow is an int. It tells me that DeleteRow is
not accessible.
DeleteRow() is declared as protected in TCustomGrid, and TStringGrid does
not provide public access to it. In order to access DeleteRow(), you need
to derive a new class and provide your own access to it, ie:
class TMyStringGrid : public TStringGrid
{
public:
__fastcall TMyStringGrid(TComponent *Owner)
: TStringGrid(Owner)
{
}
void __fastcall DeleteARow(int ARow)
{
TCustomGrid::DeleteRow(ARow);
}
};
Otherwise, you will just have to forget using the grid's DeleteRow() and
just manipulate the rows manually, ie
void __fastcall TForm1::DeleteRow(int Row)
{
if( Row>= StringGrid1->FixedRows )
{
// move the content below the desired row up a row
for(int x = Row; x < (StringGrid1->RowCount-1); ++x)
StringGrid1->Rows[x]->Assign(StringGrid1->Rows[x+1]);
// resize the grid to remove or clear the last row.
// note - the grid does not support having 0 non-fixed rows
if( StringGrid1->RowCount>(StringGrid1->FixedRows+1) )
StringGrid1->RowCount = (StringGrid1->RowCount - 1);
else
StringGrid1->Rows[StringGrid1->FixedRows]->Clear();
}
}
Gambit
 

Re:TStringGrid - how to delete a row?

Thank you - works like a charm!
Remy Lebeau (TeamB) wrote:
Quote
"Hugh W Stewart" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>I want to delete a row from a TStringGrid. I tried
>((TCustomGrid*)MyStringGrid)->DeleteRow(SelRow);
>where SelRow is an int. It tells me that DeleteRow is
>not accessible.


DeleteRow() is declared as protected in TCustomGrid, and TStringGrid does
not provide public access to it. In order to access DeleteRow(), you need
to derive a new class and provide your own access to it, ie:

class TMyStringGrid : public TStringGrid
{
public:
__fastcall TMyStringGrid(TComponent *Owner)
: TStringGrid(Owner)
{
}

void __fastcall DeleteARow(int ARow)
{
TCustomGrid::DeleteRow(ARow);
}
};

Otherwise, you will just have to forget using the grid's DeleteRow() and
just manipulate the rows manually, ie

void __fastcall TForm1::DeleteRow(int Row)
{
if( Row>= StringGrid1->FixedRows )
{
// move the content below the desired row up a row

for(int x = Row; x < (StringGrid1->RowCount-1); ++x)
StringGrid1->Rows[x]->Assign(StringGrid1->Rows[x+1]);

// resize the grid to remove or clear the last row.
// note - the grid does not support having 0 non-fixed rows

if( StringGrid1->RowCount>(StringGrid1->FixedRows+1) )
StringGrid1->RowCount = (StringGrid1->RowCount - 1);
else
StringGrid1->Rows[StringGrid1->FixedRows]->Clear();
}
}


Gambit


 

{smallsort}

Re:TStringGrid - how to delete a row?

Quote
DeleteRow() is declared as protected in TCustomGrid, and TStringGrid does
not provide public access to it. In order to access DeleteRow(), you need
to derive a new class and provide your own access to it, ie:

class TMyStringGrid : public TStringGrid
{
public:
__fastcall TMyStringGrid(TComponent *Owner)
: TStringGrid(Owner)
{
}

void __fastcall DeleteARow(int ARow)
{
TCustomGrid::DeleteRow(ARow);
}
};

Tests indicate that sometimes those methods (TCustumGrid ::DeleteRow() and
TCustumGrid ::DeleteColumn()) alter the contents of the remaing row and
columns, creating a mess with the data stored in the StringGrid's cells.
www.geocities.com/rodolfofrino/StringGridWithDeleteRow.html
Rodolfo
 

Re:TStringGrid - how to delete a row?

I wrote an article on an advance String Grid that supports both Col/Row
delete
and Col/Row insert operations as well as SaveFile and ReadFile operations
www.geocities.com/rodolfofrino/MicroStringGrid.html
Rodolfo
"Hugh W Stewart" < XXXX@XXXXX.COM >wrote in message
Quote
Help!
I want to delete a row from a TStringGrid. I tried
((TCustomGrid*)MyStringGrid)->DeleteRow(SelRow); where SelRow is an int.
It tells me that DeleteRow is not accessible.

Thanks for help
Hugh