Add a combobox in to listview control in c++ builder - c++builder

I want to create a listview with 2 columns. in the first column it must be the row number and in the second number it should contains a combobox. I write the following code, but second column just show "combo" string. it does not show any combo box. what is the wrong?
for (int i = 0; i < 10; i++) {
TListItem *items;
items= this->ListView1->Items->Add();
items->Caption=IntToStr(i);
items->SubItems->AddObject("combo"+IntToStr(i),(TObject *)this->ComboBox1);
}

It does not show a TComboBox because you have not actually set the TComboBox to be a child control of the TListView. All you have done is store the TComboBox pointer as a user-defined value associated with the TListItem. That has no effect on the UI, so get rid of it:
for (int i = 0; i < 10; i++)
{
TListItem *items = ListView1->Items->Add();
items->Caption = IntToStr(i);
items->SubItems->Add("combo"+IntToStr(i));
}
To actually show a TComboBox inside of the TListView, you have to assign the TListView as the Parent of the TComboBox, and then use the SetBounds() method to position and size the TComboBox whenever you need to show it:
ComboBox1->Parent = ListView1;
...
RECT rect = {0};
ListView_GetSubItemRect(ListView1->Handle, SomeListItem->Index, 1, LVIR_BOUNDS, &rect);
ComboBox1->SetBounds(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
// update ComboBox1->Items as needed...
ComboBox1->Visible = true;
...
ComboBox1->Visible = false;
With that said, what you are attempting to do is better handled using the TValueListEditor component instead. Add items to it as needed, then use its ItemProps property to set each item's TItemProp.EditStyle property to esPickList, and then use the TValueListEditor.OnGetPickList event or the TItemProp.PickList property to manage the ComboBox strings as needed.

Related

How to make TListView display order the same as the items were added?

I am adding a list of comet names and numbers into the VCL TListView and TListBox in C++Builder. I need the display order to be the order in which the names were added. This happens with the TListBox but not the TListView.
I am loading a .CSV file into a TStringList and then looping through the TStringList to load the contents into the TListBox and TListView. The TListBox displays the names in the order they are added. The TListView displays the names and numbers in two columns in an order I can't understand. With the TListView, I tried using the function Add() and Insert().
Below is my code. The picture shows the different results I get. How can I make the TListView display the names and numbers in the order they are added the same as the TListBox?
TListItem *ListItem;
std::auto_ptr<TStringList> MyCSVFile(new TStringList);
MyCSVFile->Delimiter = ',';
MyCSVFile->StrictDelimiter = true;
MyCSVFile->CommaText = "";
MyCSVFile->Clear();
MyCSVFile->LoadFromFile(GetFileName);
for(Row_Num=1; Row_Num < MyCSVFile->Count; Row_Num++){
Row_string = MyCSVFile->Strings[Row_Num];
Row_tokens->CommaText = Row_string;
Name_string = Row_tokens->Strings[Name_Cell_Num];
Num_string = Row_tokens->Strings[Num_Cell_Num];
ListBox1->Items->Add(Name_string);
//ListView - Add()
ListItem = ListView->Items->Add();
ListItem->Caption = Cell_string;
ListItem->SubItems->Add( Num_string );
//Alternate method ListView - Insert()
//ListItem = ListView->Items->Insert(0);
//ListItem->Caption = Cell_string;
//ListItem->SubItems->Insert(0, Num_string);
}
ListBox and ListView
I have tried using the Add() and Insert() functions with TListView but the display order is not the order items are added. I don't know any other way to get items into the TListView.
By default, the TListView sorts the items based on their captions or subitems, but setting the SortType to stNone will disable the sorting.
So, you can add the following line before the loop:
ListView->SortType = stNone;

font size and hide property for categorybuttons items in delphi

Category Buttons component hasn't font property for each categories and items separately. It also hasn't show hide properties for them. Now how can I hack Category Buttons component to do that something like the following codes :
CategoryButtons1.Categories[1].Items[1].Font.Size := 12;
CategoryButtons1.Categories[1].Font.Size := 12;
CategoryButtons1.Categories[1].Items[1].Hide;
CategoryButtons1.Categories[1].Hide;
CategoryButtons1.Categories[1].Items[1].Show;
CategoryButtons1.Categories[1].Show;
Thank you

How do I add Components dynamically during runtime in Builder XE6?

I want to add new panels to my form during runtime, but I have the problem that, when aligning them to the top, they are not displayed in the order that I created them.
I followed the hints from this post with the DisableAlign() and EnableAlign()
How to dynamically create controls aligned to the top but after other aligned controls?
This works for the initial four panels I add.
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TPanel * test;
Panel1->DisableAlign();
for(int i = 0; i<4; i++){
test = new TPanel(Panel1);
test->Caption = i;
test->Parent = Panel1;
test->Align = alTop;
}
Panel1->EnableAlign();
}
But then I want to add another panel when clicking the button:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Panel1->DisableAlign();
TPanel * test;
test = new TPanel(Panel1);
test->Caption = 5;
test->Parent = Panel1;
test->Align = alTop;
Panel1->EnableAlign();
}
and this comes up:
Is there any way to get the alignment to do what I want without messing around with the Top Settings or without rebuilding the whole form?
It's quite simple. You must set Top to an appropriate value before setting Align. Set Top to be the coordinate of the bottom of the bottom panel.

Vaadin Listbox Option Tooltip

Is it possible to add the title(tooltip) attribute to a listbox ot twincolselect in Vaadin?
I've tried to use setItemCaptionPropertyId() along with setItemCaptionMode() but in vain.
At the end when Vaadin renders the page, the resultant html has only the value attribute to the select component and no title attribute is present.
Update - my question should have been re-phrased to say - I need tooltip on each individual item (individual row) within a listbox or twinselect.
Here is an example for Nativeselect component
// Create the selection component
final NativeSelect mynativeselect= new NativeSelect("myLabel");
// Add some items
for (int i = 0; i < 25; ++i) {
mynativeselect.addItem(i);
}
//set tooltip
mynativeselect.setDescription("My tooltip");

Iterating children of a TVertScrollBox

I have a single TForm with a single TVertScrollBox. I have added 6 TPanels as children of this TVertScrollBox.
I would like to iterate over each of these panels and check the Tag property of each, but I can't find the correct method to do so.
For testing, I've added an OnClick event handler for one of the panels that contains the following code:
void __fastcall TForm1::Panel1Click(TObject *Sender)
{
int i;
for (i = 0; i < this->VertScrollBox1->ChildrenCount; ++i)
{
ShowMessage("Child: " + this->VertScrollBox1->Children[i]->Name);
}
for (i = 0; i < this->VertScrollBox1->ComponentCount; ++i)
{
ShowMessage("Component: " + this->VertScrollBox1->Components[i]->Name);
}
}
It seems the ChildrenCount property always returns 2, and the Name displayed by ShowMessage for each of these children is an empty string, even though each panel has a unique Name property.
The ComponentCount property always returns 1, and again- the displayed Name is always an empty string.
Can someone tell me which properties or methods to use to iterate over these children?
Children & ChildrenCount are the correct properties to use but it sounds like your panels are being stored in a container stored within the scrollbox. (I've seen this in other components and I'm not at my dev machine to research).
Check the Classnames of the two children, and what their children are. When you've astablished which child (identified by ClassName) is the container, you'll know how to drill down to your panels.

Resources