How can I find the index of the top item in the drop-down list of a TComboBox
?
I know that a TListBox
has a TopIndex
property, but I can't find anything similar to this for a TComboBox
.
I'm using C Builder in RAD Studio 10.4 Update 2.
CodePudding user response:
Since FMX's TListBox
does not have a TopIndex
property, I'm going to assume you are referring to VCL instead.
In the VCL, you can access the HWND
of the TComboBox
's drop-down ListBox by calling the Win32 GetComboBoxInfo()
function on (or sending a CB_GETCOMBOBOXINFO
message to) the HWND
returned by the TComboBox::Handle
property. And then you can send an LB_GETTOPINDEX
message to the ListBox HWND
.
COMBOBOXINFO info = { sizeof(COMBOBOXINFO) };
GetComboBoxInfo(ComboBox1->Handle, &info);
// or: SendMessage(ComboBox1->Handle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info);
int index = SendMessage(info.hwndList, LB_GETTOPINDEX, 0, 0);