How to make TListView display order the same as the items were added? - c++builder

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;

Related

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

TEdit and focus selection works different depending on Show/showmodal

When switching focus between TEdits, the selection changes depending on the way you show the form.
When you show it with Form.show, and swith between two TEdits, the text is selected.
When you show the form with Form.Showmodal, And switch between, the cursor is at the end of the newly focused TEdit
reproduce :
Create a new form with 2 TEdits, type some text in both. Then switch between both TEdits, the whole text is selected, but when I show the form with Modal, The caret is positioned behind the text.
Why is there a difference in functionality? And where can I change it.
I found the code responsible :
procedure TStyledEdit.DoEnter;
var
Form: TCommonCustomForm;
begin
inherited;
Form := TCommonCustomForm(Root);
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
//next part returns false
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing]) or
(Form.FormState = [TFmxFormState.Engaged])) then
Edit.SelectAll
else
begin
UpdateSelectionPointPositions;
UpdateCaretPosition;
end;
end;
DoEnter is a protected method and as such you can override with your own method if you wish.
You can either do this the classic way by creating your own descendant class (with a different type name) or you can use the so-called interceptor classes as described in this link: interceptor classes.
I believed that you need to extend the if clause like this (but not tested - sorry)
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing])
or (Form.FormState * [TFmxFormState.Modal] = [TFmxFormState.Modal])
or (Form.FormState = [TFmxFormState.Engaged])) then

Add a combobox in to listview control in 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.

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