Board index » cppbuilder » Making StringGrid Rows Invisible
Mark Jacobs
![]() CBuilder Developer |
Mark Jacobs
![]() CBuilder Developer |
Making StringGrid Rows Invisible2006-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 |
JD
![]() CBuilder Developer |
2006-02-03 02:57:24 AM
Re:Making StringGrid Rows Invisible
Mark Jacobs < XXXX@XXXXX.COM >wrote:
Quote
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 |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-02-03 03:31:09 AM
Re:Making StringGrid Rows Invisible
"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
QuoteWithout actually removing the rows from the string grid, how would QuoteI've tried making their height zero, but it still has the gridlines (which Gambit {smallsort} |
Mark Jacobs
![]() CBuilder Developer |
2006-02-03 09:46:54 PM
Re:Making StringGrid Rows Invisible
Remy Lebeau (TeamB) wrote:
Quote"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message 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 |
Mark Jacobs
![]() CBuilder Developer |
2006-02-03 09:47:50 PM
Re:Making StringGrid Rows Invisible
JD wrote:
QuoteI think that the easiest solution would be to set the Mark Jacobs www.dkcomputing.co.uk |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-02-04 04:18:20 AM
Re:Making StringGrid Rows Invisible
"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
QuoteOften, 20 or so consecutive rows are to be made invisible. The grid lines 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 |