Board index » delphi » ListBox Question (Newbie)
William Vedder
![]() Delphi Developer |
Tue, 19 Jul 2005 11:45:59 GMT
|
William Vedder
![]() Delphi Developer |
Tue, 19 Jul 2005 11:45:59 GMT
ListBox Question (Newbie)
Greetings,
I have two listboxes on a form; each has a vertical scrollbar. I am trying to understand how to read the selected item. In Delphi, does the user have to scroll thru listbox list and then select the item in the listbox before the program recognizes an item has been selected? That seems to be one step too many; the user should just have to scroll thru the list then stop at the item of choice. If there's an event or property for the listboxes that I can use to read Best, |
Vinnie Murdic
![]() Delphi Developer |
Tue, 19 Jul 2005 13:20:48 GMT
Re:ListBox Question (Newbie)You should be able to read the selected item regardless of whether the user has scrolled the listbox or clicked on it. Of course, when a list box is initially created and then populated, there is no "default" selected item, so either your application or the user must select an item in the list box as the "selected" item in order for you to recognize it in your code. To get the currently selected item, use: var Of couse, you must check if ItemIndex <> -1 first before referencing items Your app can initially set the first item in the list as the default If (Listbox1.Items.Count > 0) Then Hope this helps. -- |
William Vedde
![]() Delphi Developer |
Wed, 20 Jul 2005 20:37:09 GMT
Re:ListBox Question (Newbie)Thanks for your reply. I used your code example to get the values but I still only get the listbox values to update when the user both scrolls then selects an entry from the list. I use showmessage() to test the code. Here's some of the code: procedure TMainForm.FormCreate(Sender: TObject); The user can make parameter selections from the listboxes or accept the procedure TMainForm.bStartClick(Sender: TObject); //grab the kernel type //grab the dimension .... When I run this code, the background color of the listboxes on my I don't know what's going on... Bill "Vinnie Murdico" <vin...@softwarewithbrainsSPAMKILL.com> wrote in Quote> You should be able to read the selected item regardless of whether the |
AlanGLLo
![]() Delphi Developer |
Wed, 20 Jul 2005 21:58:05 GMT
Re:ListBox Question (Newbie)In article <Xjm_9.6267$ZX5.169...@twister.austin.rr.com>, "William Vedder" Quote<wved...@houston.rr.com> writes: item has been selected, then TListBox.ItemIndex is set to the index of the selected item. That selection and ItemIndex remains as ir was set even if the listbox is scrolled. The user can select an item _only_ by clicking on it (multi-select selects While a TListBox has a TopIndex which reads or sets the item at the top of a I think you cannot do what you appear to want to do. Alan Lloyd |
William Vedde
![]() Delphi Developer |
Thu, 21 Jul 2005 03:46:19 GMT
Re:ListBox Question (Newbie)Thanks Alan. I was hoping that there was an "onchange" event or something that I was missing. It seems senseless to have to scroll AND select. Best, Quote"AlanGLLoyd" <alangll...@aol.com> wrote in message Quote> In article <Xjm_9.6267$ZX5.169...@twister.austin.rr.com>, "William |
John of Ai
![]() Delphi Developer |
Thu, 21 Jul 2005 03:33:44 GMT
Re:ListBox Question (Newbie)Please don't include attached files with your messages. Post the code if necessary (and not too long). |
AlanGLLo
![]() Delphi Developer |
Thu, 21 Jul 2005 04:09:49 GMT
Re:ListBox Question (Newbie)In article <fuV_9.12285$2y.582...@twister.austin.rr.com>, "William Vedder" Quote<wved...@houston.rr.com> writes: wants to select. Or are you displaying only one item as the scrolling takes place. If that's the case, then there are other ways of doing that sort of thing. Alan Lloyd |
William Vedde
![]() Delphi Developer |
Thu, 21 Jul 2005 06:10:42 GMT
Re:ListBox Question (Newbie)Yes, I have sized the listboxes such that the user sees only one item at a time. I am interested to hear other suggestions besides a listbox... I looked at doing this w/ radio buttons but that's ugly. Bill Quote"AlanGLLoyd" <alangll...@aol.com> wrote in message Quote> In article <fuV_9.12285$2y.582...@twister.austin.rr.com>, "William |
William Vedde
![]() Delphi Developer |
Thu, 21 Jul 2005 06:12:54 GMT
Re:ListBox Question (Newbie)I apologize for the attachment but that's not what I sent or at least intended to send. I cut/pasted some code into my email response. I don't know how it ended up as an attachment. Best, Quote> Please don't include attached files with your messages. Post the code |
Maarten Wiltin
![]() Delphi Developer |
Thu, 21 Jul 2005 06:18:55 GMT
Re:ListBox Question (Newbie)QuoteWilliam Vedder wrote in message ... In normal listboxes, you can scroll the selection out of sight. A propos the radio buttons versus the dropdown-listbox, this is Groetjes, |
AlanGLLo
![]() Delphi Developer |
Thu, 21 Jul 2005 15:08:51 GMT
Re:ListBox Question (Newbie)In article <CBX_9.12382$2y.610...@twister.austin.rr.com>, "William Vedder" Quote<wved...@houston.rr.com> writes: follows ... var procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType); Alan Lloyd |
Ulrich Gerhard
![]() Delphi Developer |
Sat, 23 Jul 2005 03:37:09 GMT
Re:ListBox Question (Newbie)QuoteMaarten Wiltink wrote: by typing its initial letter. Nevertheless the old design was better IMHO, too. Uli. |