Board index » cppbuilder » TStringGrid with MultiSelect

TStringGrid with MultiSelect


2007-04-02 03:06:59 AM
cppbuilder19
I'm looking for a freeware component which extends TStringGrid to include
multiple row selection. I'm using C Builder 6.0.
Can somebody give me a pointer? I've done a search but can not seem to find
a component that works.
Thanks
 
 

Re:TStringGrid with MultiSelect

"None" < XXXX@XXXXX.COM >wrote:
Quote

I'm looking for a freeware component which extends
TStringGrid to include multiple row selection.
That's easy enough to code yourself. All you need is a dynamic
array (you can even use the Objects property) to track which
rows are selected and then some sort of UI rules to know when
to add a row as selected and when to clear a row or all rows
as selected.
Assuming that you descide to use the Objects property and
Ctrl + Left Mouse Button to select/deselect, all you need to
do is add OnMouseDown event to the grid. You'll also want to
set the grid's DefaultDrawing property to false and add an
OnDrawCell event so that you can provide visual feedback
to the user as to his/her choice of selection. For example:
//-------------------------------------------------------------
void __fastcall TForm1::GridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Button == mbLeft && Shift.Contains(ssCtrl) )
{
int ACol, ARow;
TStringGrid *Grid = static_cast<TStringGrid*>( Sender );
Grid->MouseToCell( X, Y, ACol, ARow );
if( ACol>-1 && ARow>-1 )
{
if( Objects[0][ARow] ) Objects[0][ARow] = reinterpret_cast<TObject*>( 0 );
else Objects[0][ARow] = reinterpret_cast<TObject*>( 1 );
Grid->Invalidate();
}
}
}
//-------------------------------------------------------------
void __fastcall TForm1::GridDrawCell(TObject *Sender, int ACol, int ARow, const TRect &Rect, TGridDrawState State)
{
TStringGrid *Grid = static_cast<TStringGrid*>( Sender );
TCanvas *pCanvas = Grid->Canvas;
TRect R = Rect;
if( State.Contains(gdFixed) )
{
pCanvas->Brush->Color = Grid->FixedColor;
pCanvas->Font->Color = Grid->Font->Color;
}
else
{
if( Grid->Objects[0][ARow] )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = Grid->Color;
pCanvas->Font->Color = Grid->Font->Color;
}
}
pCanvas->FillRect( R );
::DrawText( pCanvas->Handle, Grid->Cells[ACol][ARow].c_str(), -1, &R, DT_SINGLELINE | DT_LEFT | DT_VCENTER );
if( State.Contains(gdFocused) )
{
// draw focus rect
}
}
//-------------------------------------------------------------
I'd also add a PopupMenu with options to Select/Unselect All.
For example:
//-------------------------------------------------------------
void __fastcall TForm1::GridSelectAll(TObject *Sender)
{
TObject *Obj = reinterpret_cast<TObject*>( 1 );
for( int ARow = Grid->FixedRows; ARow < Grid->RowCount; ++ARow )
{
Grid->Objects[0][ARow] = Obj;
}
Grid->Invalidate();
}
//-------------------------------------------------------------
~ JD
 

Re:TStringGrid with MultiSelect

Take a look at TMS Software - I've been using their
TAdvStringString for quite a few projects and have been more than
satisfied.
"None" < XXXX@XXXXX.COM >wrote:
Quote
I'm looking for a freeware component which extends TStringGrid to include
multiple row selection. I'm using C Builder 6.0.

Can somebody give me a pointer? I've done a search but can not seem to find
a component that works.

Thanks


 

{smallsort}

Re:TStringGrid with MultiSelect

"Brian" < XXXX@XXXXX.COM >wrote:
Quote

Take a look at TMS Software - I've been using their
TAdvStringString for quite a few projects and have been more
than satisfied.
Except that the TMS grid is not freeware, not even the Lite
version shipped on the companion tools cd. It's OK for
personal use, but not for distribution.