Board index » delphi » List-Boxes and Combo-Boxes

List-Boxes and Combo-Boxes

Hello Everybody,
I think I have figured out for myself, how to create buttons and stuff
in the main windows, but now I have another problem:
How can I add Strings to a List- or Combo-Box in a dialog/in the main
window and how can I read the current selection?

Thanks very much,
 Timo

 

Re:List-Boxes and Combo-Boxes


Quote
predator (timo.kreu...@ploe.comcity.de) wrote:
> Hello Everybody,
> I think I have figured out for myself, how to create buttons and stuff
> in the main windows, but now I have another problem:
> How can I add Strings to a List- or Combo-Box in a dialog/in the main
> window and how can I read the current selection?

To add stings to a listbox, use LB_ADDSTRING message. To
get the current selection use LB_GETCURSEL. For example

  var
    szItem: array[0..50] of Char;
    SelIndex: Integer;
  begin
    { Add a string to a listbox with handle in hwndList }
    lstrcpy(szItem, 'abcd');
    SendMessage(hwndList, lb_AddString, 0, Longint(@szItem));

    { Get the index of the selected item }
    SelIndex := SendMessage(hwndList, lb_GetCurSel, 0, 0);

--
Jouko Kynsijarvi
kynsi...@myy.helbp.fi

Re:List-Boxes and Combo-Boxes


Timo asked ...
   How do I add string to list boxes / combo boxes.

Send the list box a message.
     SendMessage(AListBox^.HWindow, lb_AddString, 0, longint(AString));
     AListBox is of type PListBox, AString is of type PChar
     The first parameter is the list boxes handle.
     The second is the message you want to be sent.
     The third parameter is not used.
     The fourth parameter is a pointer to a string that will be added.

Timo asked ...
   How do I get the current selection for list boxes / combo boxes.

Send the list box a message.
     RV := SendMessage(AListBox^.HWindow, lb_GetCurSel, 0, 0);
     RV  is an integer, AListBox is a PListBox.
     RV will be the index of the selected item.  RV will equal lb_Err if nothing is selected

I use Borland's TPW 1.5.  There is an extensive set of on-line help under "LB_".
For combo boxes the messages start with cb_ instead of lb_.

Also, with regards to filling list and combo boxes, look up at TransferData command.
Using this you can pass the list box a Collection of strings, thus populating the list with
all of the strings at once.

Hope this helps.

Malcolm J. Jones
TELUS Corporation

Re:List-Boxes and Combo-Boxes


Quote
predator wrote:
>...
> How can I add Strings to a List- or Combo-Box in a dialog/in the main
> window and how can I read the current selection?
>...Look under lb_addstring, lb_getcursel, and cb_??? equivalents. These

messages should do what you want. Using OWL, the list- and combobox
objects have corresponding methods (see documentation/online help).

Succes,

Remco

--------------------------------------------------------------------------------
This is an automatically generated signature for Remco Vietor in
netscape.
The views expressed in this message should be taken as the personal views
of
the author, unless stated otherwise.

Other Threads