List boxes in VFP 6.0 - selected property won't set in form's init 
Author Message
 List boxes in VFP 6.0 - selected property won't set in form's init

I've just found some really bizarre behaviour regarding listboxes.

I have a form which produces one of several reports depending on a
parameter passed to the form's init. To give users flexibility they can
switch reports once the form is loaded by selecting one of the other
available reports from a list-box.

To show the user the currently selected report in the list box, my init
contains the following code:

LPARAMETERS opt3
LOCAL cc
cc = AT(opt3,"ABCDEFGH")
THIS.List1.Selected[cc] = .T.
THIS.List1.TopItemId = cc

The last two lines do not do anything, nothing is selected in the list
box and the first item is still at the top.

If I go into the de{*filter*} and break when cc changes and step through the
code, the de{*filter*} shows '.F.' if I put the cursor above the
'THIS.List1.Selected[cc]' until I step off the line, after which it
(correctly) shows 'T'. When I go back to the form, the correct item is
highlighted and at the top of the listbox.

If, in the de{*filter*}, I don't evaluate 'THIS.List1.Selected[cc]' prior to
the line of code being executed, the effect is the same as when the
de{*filter*} isn't running, i.e. nothing is selected and item 1 stays top.

Anyone got any ideas what's going on here??

Am  I doing something daft?

It worked OK on VFP 3.0.

I figured that VFP 6.0 needs something to evaluate THIS.List1.Selected[]
before it will let me set a value so I have added the line:

    dummy = THIS.List1.Selected[cc]

immediately prior to the line 'THIS.List1.Selected[cc] = .T.' and it
works fine every time.
--
Richard Candeland



Fri, 03 May 2002 03:00:00 GMT  
 List boxes in VFP 6.0 - selected property won't set in form's init
Try setting focus to the list after you've selected to item you want.


Quote:
> I've just found some really bizarre behaviour regarding listboxes.

> I have a form which produces one of several reports depending on a
> parameter passed to the form's init. To give users flexibility they can
> switch reports once the form is loaded by selecting one of the other
> available reports from a list-box.

> To show the user the currently selected report in the list box, my init
> contains the following code:

> LPARAMETERS opt3
> LOCAL cc
> cc = AT(opt3,"ABCDEFGH")
> THIS.List1.Selected[cc] = .T.
> THIS.List1.TopItemId = cc

> The last two lines do not do anything, nothing is selected in the list
> box and the first item is still at the top.

> If I go into the de{*filter*} and break when cc changes and step through the
> code, the de{*filter*} shows '.F.' if I put the cursor above the
> 'THIS.List1.Selected[cc]' until I step off the line, after which it
> (correctly) shows 'T'. When I go back to the form, the correct item is
> highlighted and at the top of the listbox.

> If, in the de{*filter*}, I don't evaluate 'THIS.List1.Selected[cc]' prior to
> the line of code being executed, the effect is the same as when the
> de{*filter*} isn't running, i.e. nothing is selected and item 1 stays top.

> Anyone got any ideas what's going on here??

> Am  I doing something daft?

> It worked OK on VFP 3.0.

> I figured that VFP 6.0 needs something to evaluate THIS.List1.Selected[]
> before it will let me set a value so I have added the line:

>     dummy = THIS.List1.Selected[cc]

> immediately prior to the line 'THIS.List1.Selected[cc] = .T.' and it
> works fine every time.
> --
> Richard Candeland



Fri, 03 May 2002 03:00:00 GMT  
 List boxes in VFP 6.0 - selected property won't set in form's init

Quote:
> Anyone got any ideas what's going on here??

No, but...

In the Init() of the form I would say:

LPARAMETERS opt3
THIS.List1.Value = opt3     &&  a string in the displayed list

or, if the parameter is numeric,

THIS.List1.ListIndex = opt3

Watch out for the data source of the list. I've messed things up by changing
the value in a table instead of setting a property. Oops.

Not sure if this helps.

Dan


Quote:
> I've just found some really bizarre behaviour regarding listboxes.

> I have a form which produces one of several reports depending on a
> parameter passed to the form's init. To give users flexibility they can
> switch reports once the form is loaded by selecting one of the other
> available reports from a list-box.

> To show the user the currently selected report in the list box, my init
> contains the following code:

> LPARAMETERS opt3
> LOCAL cc
> cc = AT(opt3,"ABCDEFGH")
> THIS.List1.Selected[cc] = .T.
> THIS.List1.TopItemId = cc

> The last two lines do not do anything, nothing is selected in the list
> box and the first item is still at the top.

> If I go into the de{*filter*} and break when cc changes and step through the
> code, the de{*filter*} shows '.F.' if I put the cursor above the
> 'THIS.List1.Selected[cc]' until I step off the line, after which it
> (correctly) shows 'T'. When I go back to the form, the correct item is
> highlighted and at the top of the listbox.

> If, in the de{*filter*}, I don't evaluate 'THIS.List1.Selected[cc]' prior to
> the line of code being executed, the effect is the same as when the
> de{*filter*} isn't running, i.e. nothing is selected and item 1 stays top.

> Anyone got any ideas what's going on here??

> Am  I doing something daft?

> It worked OK on VFP 3.0.

> I figured that VFP 6.0 needs something to evaluate THIS.List1.Selected[]
> before it will let me set a value so I have added the line:

>     dummy = THIS.List1.Selected[cc]

> immediately prior to the line 'THIS.List1.Selected[cc] = .T.' and it
> works fine every time.
> --
> Richard Candeland



Fri, 03 May 2002 03:00:00 GMT  
 List boxes in VFP 6.0 - selected property won't set in form's init
Richard
Well that depends on what you expect setting TopItemId to do. It certainly
doesn't move a row to the top. In a combobox the line
THIS.List1.Selected[cc] = .T. will make the  intended row show up in the
textbox as DisplayValue. The only use for TopItemId I've found is to get the
real itemid of the first item in a sorted list that's not been entered in
alphabetical order.
-Anders


| I've just found some really bizarre behaviour regarding listboxes.
|
| I have a form which produces one of several reports depending on a
| parameter passed to the form's init. To give users flexibility they can
| switch reports once the form is loaded by selecting one of the other
| available reports from a list-box.h
|
| To show the user the currently selected report in the list box, my init
| contains the following code:
|
p| LPARAMETERS opt3
| LOCAL cc
| cc = AT(opt3,"ABCDEFGH")
| THIS.List1.Selected[cc] = .T.
| THIS.List1.TopItemId = cc
|
| The last two lines do not do anything, nothing is selected in the list
| box and the first item is still at the top.
|
| If I go into the de{*filter*} and break when cc changes and step through the
| code, the de{*filter*} shows '.F.' if I put the cursor above the
| 'THIS.List1.Selected[cc]' until I step off the line, after which it
| (correctly) shows 'T'. When I go back to the form, the correct item is
| highlighted and at the top of the listbox.
|
| If, in the de{*filter*}, I don't evaluate 'THIS.List1.Selected[cc]' prior to
| the line of code being executed, the effect is the same as when the
| de{*filter*} isn't running, i.e. nothing is selected and item 1 stays top.
|
| Anyone got any ideas what's going on here??
|
| Am  I doing something daft?
|
| It worked OK on VFP 3.0.
|
| I figured that VFP 6.0 needs something to evaluate THIS.List1.Selected[]
| before it will let me set a value so I have added the line:
|
|     dummy = THIS.List1.Selected[cc]
|
| immediately prior to the line 'THIS.List1.Selected[cc] = .T.' and it
| works fine every time.
| --
| Richard Candeland



Fri, 03 May 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VFP 7: Grid Combo Box won't keep selected item

2. Setting a parameterized view in form's Init

3. List Box, I just can't win

4. Q: Cursor's Exclusive property in a form's datasession

5. VFP6: 'No Init' Option on 'Edit Property/Method' Screen

6. BUG: Printer Fonts Won't Stay Selected in VFP Report Designer

7. VFP 5.0 - Combo box won't sort!

8. Pause on vfp's combo box under Win XP

9. Referring to property within select statement in list/combo box rowsource

10. Referring to property within select statement in list/combo box rowsource

11. Changing one form's properties from a different form

12. Top Level Form, Menus and Form's Properties

 

 
Powered by phpBB® Forum Software