Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you select items in a listbox by value?
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00453572
Message ID:
00453587
Views:
26
>>Do you have the control source set too? The RowSource defines the list, the ControlSource is the value of that list. If it is set, do you refresh() it after moving the pointer?
>
>I had the ControlSource set, but when I select a value in the listbox, the pointer in the listbox keeps jumping to the top of the list... it's really weird. So I had to clear the ControlSource and now set thisform.cCoName = this.value in the InteractiveChange...
>
>As the user moves through the listbox containing company names, textboxes on the form display other info about the company. The problem comes when I add a new company to the table. After the company gets added to the table, I would like the listbox to jump to that new value after issuing a refresh. The only way I could figure to do this now, was to try and select the new company's name in the listbox directly... without knowing the nIndex or ItemID that is...
>
>If I can't figure out why the list selection jumps to the top when a ControlSource is set, I'll give Trey's suggestion a try...
>
>- Brian
Brian,

Does this code help you? I posted it once today, but I don't remember, who asked about it.
********************************************************************
*  Description.......: BTCC_MultiList.BTC_ListSelect: method to select a comma-delimited list of codes
*  Calling Samples...:
*  Parameter List....: list_arg
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 01/14/2000 04:07:16 PM
********************************************************************
* 8/4/99: Adapted from preliminary logic for handling the Counties listbox.
* 12/14/99 NN changed the code to better handle lost of items selected (AT instead of INLI)
* This method is used for state-saving/restoration of the listbox.
*
* Note that the behavior of this method is additive, to allow for anticipated need to
* split up steps due to VFP's 256 character macro/expression length limit.

lparameters list_arg     && takes 1 required arg
* list_arg:                    list of codes, in a form suitable for arglist to inlist().
if alen(this.btcValArray) <= 1          && array is empty
     return                                   && no-op
endif

with this
     if empty(list_arg)
          list_arg=.btcCrit
     endif

     local n, lnSel,  lnCodes, lnLen

* check for empty array special case

     lnLen=alen(.btcValArray, 1)
* loop over the array, checking each item against the given list
     for n = 1 to lnLen                    && cycle over rows
          if at(.btcValArray[m.n, 2], list_arg)>0     && this item is to be selected
               .Container1.List1.selected(m.n) = .t.     && flag list item as Selected
          endif
     endfor

     if !empty(.TableName)
          lnSel=select() && save current area

          select (.TableName)

          if reccount()<1 and !empty(list_arg) && First time
               local array laCodes[1]
               lnCodes=aparser1(@laCodes, list_arg,',')
               for i=1 to lnCodes
                    insert into (.TableName) values (laCodes[i])
               next
               if !empty(.InputClass)
                    lObj=evaluate('this.container1.'+.InputClass+'1')
                    lObj.requery()
               endif
          endif
          select (lnSel) && return to previous area
     endif
endwith
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform