Board index » cppbuilder » HeaderControl addition

HeaderControl addition


2005-07-23 04:47:02 AM
cppbuilder100
I have a HeaderControl positioned over a CheckListBox, and I
would like to do the following:
When the application loads, CheckListBox loads a file with
containing numerous items. The HeaderControl is merely for
looks. What I want to do is change the HeaderControl's "caption"
to reflect the number of items in the CheckListBox below.
The caption as it is now is just "Employees" What I'm wanting to do is just add the total count of item to the header information.
Employees: 5
-------------
Name
Name
Name
Name
Name
This list will obviously change when items are added or removed, so the change would need to be updated. I prefer
that this be done when I open the application, as the items
are loaded into the CheckListBox at start up.
 
 

Re:HeaderControl addition

"metal.c" < XXXX@XXXXX.COM >wrote in message
Quote
I have a HeaderControl positioned over a CheckListBox, and
I would like to do the following:
So what is the actual problem you are having? THeaderControl has a Sections
collection, and each Section has a Text property. Every time you do
something to the CheckListBox, simply update the Text accordingly.
Incidently, you could use a TListView instead of a TCheckListBox. TListView
has build-in column headers, and a CheckBoxes property.
Gambit
 

Re:HeaderControl addition

Quote
So what is the actual problem you are having?
The problem is not knowing how to do it. I tried, but I
couldn't get it to work... I looked in the help files, and
tried various things, but I didn't have any luck.
Thanks
 

{smallsort}

Re:HeaderControl addition

"metal.c" < XXXX@XXXXX.COM >wrote in message
Quote
The problem is not knowing how to do it. I tried, but I
couldn't get it to work... I looked in the help files, and
tried various things, but I didn't have any luck.
What EXACTLY doesn't work for you? You need to be more specific.
Gambit
 

Re:HeaderControl addition

Quote
You need to be more specific.
I don't know you get any more specific than:
"The problem is not knowing how to do it."
I removed the code that I was playing with since it didn't work. I saw no point in commenting a chunk of code that was
useless.
I'll try iy again later, and post a follow up, if that's what
you insist upon me having to do to get an answer. I'm sorry
that I'm not a veteran coder. I just make do with what I have...
 

Re:HeaderControl addition

Hi,
You can access the individual sections of the THeaderControl by using
the Sections::Items property; for example...
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
CheckListBox1->Items->Add("Name 1");
CheckListBox1->Items->Add("Name 2");
CheckListBox1->Items->Add("Name 3");
CheckListBox1->Items->Add("Name 4");
CheckListBox1->Items->Add("Name 5");
// add a single section, if needed (though,
// it sounds like you've already done this
// at design-time)
if (HeaderControl1->Sections->Count < 1)
{
HeaderControl1->Sections->Add();
}
// change the caption of the section
HeaderControl1->Sections->Items[0]->Text =
"Employees: " + IntToStr(CheckListBox1->Count);
}
Also, as Remy suggested, you might want to have a look at using a
TListView component (I'd be happy to post a code example, if needed).
Best of luck,
metal.c wrote:
Quote
I have a HeaderControl positioned over a CheckListBox, and I
would like to do the following:

When the application loads, CheckListBox loads a file with
containing numerous items. The HeaderControl is merely for
looks. What I want to do is change the HeaderControl's "caption"
to reflect the number of items in the CheckListBox below.
 

Re:HeaderControl addition

The following shows me the number of items in the TCheckListBox.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (CheckListBox1->Items->Count)
{
ShowMessage(CheckListBox1->Items->Count);
//X
}
}
I double click the sections property of THeaderControl, and
add my text:
Catalog Numbers
Now to the //X. At this point it's time to add the code that
will append the amount of items in the TChecklistBox to the
Header's section text.
As I pointed out previously, I did try do this own my own. I did partially suceed in getting the amount to display on the
header, but it was the text (mentioned before as caption) for a new section, and that's not what I want...
Among the numerous things I tried was:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (CheckListBox1->Items->Count)
{
ShowMessage(CheckListBox1->Items->Count);
HeaderControl1->Sections[i]->Text("Catalog Numbers: "+CheckListBox1->Items->Count);
}
}
I wasn't able to figure out how to change the sections text...
Ok.
 

Re:HeaderControl addition

Ok, thank you. Sorry being frustrated, I just want to learn :)
 

Re:HeaderControl addition

I forgot to ask for the ListView example. I copy examples to a
text file to reference later, when I need them.
 

Re:HeaderControl addition

Sure thing; drop a TListView (ListView) on your form, and then use the
following code...
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// use check boxes
ListView1->Checkboxes = true;
// use the column-type display style
ListView1->ViewStyle = vsReport;
// load your data from your file (here,
// I'll hard-code the items)
ListView1->Items->Add()->Caption = "Name 1";
ListView1->Items->Add()->Caption = "Name 2";
ListView1->Items->Add()->Caption = "Name 3";
ListView1->Items->Add()->Caption = "Name 4";
ListView1->Items->Add()->Caption = "Name 5";
// add a column
TListColumn* Column = ListView1->Columns->Add();
// set the column's caption
Column->Caption = "Employees: " +
IntToStr(ListView1->Items->Count);
// set the column's width (ColumnHeaderWidth
// is a predefined constant that will instruct
// the column to occupy the full width)
Column->Width = ColumnHeaderWidth;
}
Note that many of these properties can be set at design-time (e.g.,
TListView::Checkboxes, ViewStyle, and adding the column). Also, to
access the individual items of the list view, you'd use the
Items::Item[] property; for example...
// set the second item's caption
ListView1->Items->Item[1]->Caption = "John Doe";
The TListView::Items property returns a pointer to a TListItems object,
and the TListItems::Item[] property returns a pointer to an individual
TListItem. So, to modify an individual item, you use properties of the
TListItem class (e.g., the TListItem::Caption property in the above
example or the TListItem::Checked property).
There are also some miscellaneous articles on list views here...
bcbjournal.com/bcbcaq/
HTH,
C++Builder Developer's Journal
bcbjournal.com
BCB Commonly Asked Questions
bcbjournal.com/bcbcaq
metal.c wrote:
Quote
I forgot to ask for the ListView example. I copy examples to a
text file to reference later, when I need them.
 

Re:HeaderControl addition

"metal.c" < XXXX@XXXXX.COM >wrote in message
Quote
I don't know you get any more specific than:

"The problem is not knowing how to do it."
I already told you what to do:
"THeaderControl has a Sections collection, and each Section has a Text
property. Every time you do something to the CheckListBox, simply update
the Text accordingly."
What EXACTLY don't you understand about that? Did you even look in the
documentation?
Gambit
 

Re:HeaderControl addition

<Metal.c Specifics>wrote in message
Quote
As I pointed out previously, I did try do this own my own. I did partially
suceed in getting the amount to display on the header, but it was the text
(mentioned before as caption) for a new section, and that's not what I
want...
Setting the Text for an existing Section DOES NOT add a new Section.
Quote
HeaderControl1->Sections[i]->Text("Catalog Numbers:
"+CheckListBox1->Items->Count);
That will not work. Asside from the fact that the Sections property does
NOT have an '[]' operator to begin with, the Text is a property, not
function. Also, you are adding an int to a char* pointer. You need to cast
one of them to an AnsiString first.
Use this code instead:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HeaderControl1->Sections->Items[SomeIndex]->Text = "Catalog Numbers:
" + AnsiString(CheckListBox1->Items->Count);
}
Gambit