Board index » cppbuilder » Making StringGrid Rows Invisible

Making StringGrid Rows Invisible


2006-02-02 11:11:37 PM
cppbuilder40
I have a string grid and next to it is a combobox which is supposed to filter out certain
rows from showing in the grid. Without actually removing the rows from the string grid,
how would I make them completely invisible to the end user? I've tried making their height
zero, but it still has the gridlines (which I want to keep).
--
Mark Jacobs
www.dkcomputing.co.uk
 
 

Re:Making StringGrid Rows Invisible

Mark Jacobs < XXXX@XXXXX.COM >wrote:
Quote

[...] but it still has the gridlines (which I want to keep).
I think that the easiest solution would be to set the
GridLineWidth property to zero and draw the grid lines
yourself in the OnDrawCell event. If you go this way,
you only want to draw the grid line to the right and to
the bottom of the cell.
Otherwise, you would need to check if the row above is
invisible and inflate the Rect parameter (OnDrawCell event)
so that you paint over the above extra line(s). I see this as
problematic because you could have multiple consecutive
invisible rows which would mean that you would need to adjust the first next visible row's height so that it doesn't look
funcky.
~ JD
 

Re:Making StringGrid Rows Invisible

"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
Quote
Without actually removing the rows from the string grid, how would
I make them completely invisible to the end user?
Use the RowHeights property.
Quote
I've tried making their height zero, but it still has the gridlines (which
I want to keep).
So what is the problem exactly?
Gambit
 

{smallsort}

Re:Making StringGrid Rows Invisible

Remy Lebeau (TeamB) wrote:
Quote
"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
news:43e2204c$ XXXX@XXXXX.COM ...

>Without actually removing the rows from the string grid, how would
>I make them completely invisible to the end user?

Use the RowHeights property.

>I've tried making their height zero, but it still has the gridlines (which
>I want to keep).

So what is the problem exactly?
Often, 20 or so consecutive rows are to be made invisible. The grid lines congregate
together to make blocks of solid colour! I have just shown my boss what it looks like
without grid lines (width 0) and he has approved it, so I no longer have these colour
blocks. There remains the problem of the page up/down and arrow up/down keys not moving as
expected when invisible rows are present. It is a bit of a chore!
Thanks for your and JD's suggestions.
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Making StringGrid Rows Invisible

JD wrote:
Quote
I think that the easiest solution would be to set the
GridLineWidth property to zero and draw the grid lines
yourself in the OnDrawCell event. If you go this way,
you only want to draw the grid line to the right and to
the bottom of the cell.

Otherwise, you would need to check if the row above is
invisible and inflate the Rect parameter (OnDrawCell event)
so that you paint over the above extra line(s). I see this as
problematic because you could have multiple consecutive
invisible rows which would mean that you would need to adjust the first next visible row's height so that it doesn't look
funcky.
Thanks. Please see my reply to Remy.
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Making StringGrid Rows Invisible

"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
Quote
Often, 20 or so consecutive rows are to be made invisible. The grid lines
congregate together to make blocks of solid colour! I have just shown my
boss what it looks like without grid lines (width 0) and he has approved
it, so I no longer have these colour blocks. There remains the problem of
the page up/down and arrow up/down keys not moving as expected when
invisible rows are present. It is a bit of a chore!
I would suggest you consider using a different component altogether. A
virtual ListView in vsReport mode would work very well for everything you
have been asking for - invisible items, proper scrolling, and proper grid
lines.
For example (untested):
--- Unit1.h ---
#include <vector>
#include <algorithm>
struct TMyData
{
// change the names and types as desired ...
AnsiString Column1;
AnsiString Column2
AnsString Column3;
};
typedef std::vector<TMyData>MyDataVector;
typedef MyDataVector::iterator MyDataIter;
typedef std::vector<MyDataVector::size_type>FilterVector;
FilterVector::iterator FilterIter;
class TForm1 : public TForm
{
private:
MyDataVector MyItems;
FilterVector FilteredItems;
//...
};
--- Unit1.cpp ---
#include "Unit1.h"
void __fastcall TForm1::FilterComboBoxChange(TObject *Sender)
{
FilteredItems.clear();
MyDataVector::size_type count = MyItems.size();
for(MyDataVector::size_type idx = 0; idx < count; ++idx)
{
if( MyItems[idx] should be displayed )
FilteredItems.push_back(idx);
}
ListView1->Items->Count = FilteredItems.size();
ListView1->Invalidate();
}
void __fastcall TForm1::AddButtonClick(TObject *Sender)
{
TMyData Data;
Data.Column1 = "...";
Data.Column2 = "...";
Data.Column3 = "...";
MyItems.push_back(Data);
if( Data should be displayed )
{
FilteredItems.push_back(MyItems.size() - 1);
ListView1->Items->Count = FilteredItems.size();
ListView1->Invalidate();
}
}
void DoDecrement(FilterVector::reference Value) { --Value; }
void __fastcall TForm1::RemoveButtonClick(TObject *Sender)
{
TListItem *Selected = ListView1->Selected;
if( Selected )
{
FilterIter iter = (FilteredItems.begin() + Selected->Index);
MyDataItr iter2 = (MyItems.begin() + *iter);
std::for_each(iter+1., FilteredItems.end(); DoDecrement);
FilteredItems.remove(iter);
MyItems.remove(iter2);
ListView1->Items->Count = FilteredItems.size();
ListView1->Invalidate();
}
}
void __fastcall TForm1::DoSomething()
{
TListItem *Selected = ListView1->Selected;
if( Selected )
{
TMyData *Data = static_cast<TMyData*>(Selected->Data);
// use Data as needed ...
}
}
// set the TListView's OwnerData property to true.
void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem *Item)
{
MyDataVector::size_type DataIndex = FilteredItems[Item->Index];
TMyData *Data = &MyItems[DataIndex];
Item->Caption = Data->Column1;
Item->SubItems->Add(Data->Column2);
Item->SubItems->Add(Data->Column3);
Item->Data = Data;
}
Gambit