I am attempting to add a TEdit
control to a TListView
control during run time. I want to parent the TEdit
control to the selected TListViewItem
belonging to my TListView
, however, I cannot find a way to do this.
Originally, I tried this:
TEdit * MyEdit = new TEdit( this );
MyEdit->Parent = MyListView->Selected;
However, this gives me the following error:
[bcc32 Error] E2034 Cannot convert 'TListViewItem *' to 'TFmxObject *'
On a whim, I attempted to typecast the selected item on my list view as a TFmxObject
like so:
MyEdit->Parent = (TFmxObject *)MyListView->Selected;
While this compiled, this caused an access violation at run time.
I have searched through a lot of documentation and forum posts and cannot find very much information about dynamically adding a control to a list view item in code. I have seen solutions which propose using the style editor, but I want to avoid that if at all possible.
How can I set the parent of a control to an item in my TListView
? Is there a better / more proper way to add controls to a TListViewItem
during runtime?
According to Embarcadero documentation, TListViewItem
is not a TFmxObject
descendant and thus it can not be set as a Parent
to the desired TEdit
instance. It does not have Children
property as well. Nor do the TextObject
, DetailObject
etc. (the TListItemObject
descendants contained in TListViewItem
) ascend from TFmxObject
.
It seems you have the following ways out.
ListViewItem
class and implement it inside your ListView
s orTListBox
instead. TListBoxItem
s can parent other controls.