TechGrrl21
Programmer
I am having an issue with a form preselecting listbox values. I have a form that has a grid with a button that pops up a different form on top with a listbox. In this listbox, the user may select records that are saved to dbf. If the user is editing their records I need the second form to open with the preselected values that were saved to the table. Now, I have looked through the forum and found that setting the focus to the listbox before selecting the listbox records should keep the listbox from losing the selected values. And this helps, but does not solve the issue. Most of the time, values are preselected without issues, but sometimes, the listbox initializes with no selections. I have commented out code that calls to anything but Load and the function that populates the preselection of the listbox. Still no help. I have tried moving the function to different parts of the form such as, the Init of the form, Init of the listbox, GotFocus of the listbox...I have tried changing the Tab order as well as disabling Tabbing to the listbox. Still no better. I have tried moving the SetFocus of the Listbox to different parts of the form, from the Activate and Init to before and after the the Preselect Function..
The listbox RowSource is set to a table and the RowSourceType is Alias. I have tried Field and Value as the RowSourceType but haven't had any luck there either. I have included my code below.
I'm not discounting the idea that the class for the form may be causing issues, but I'm not catching anything from the debugger. I don't see it going through class code after it runs this function. Would any of you lovely people have any suggestions??
The listbox RowSource is set to a table and the RowSourceType is Alias. I have tried Field and Value as the RowSourceType but haven't had any luck there either. I have included my code below.
Code:
SELECT Table1
thisform.ListBox.RowSource = 'AliasedTable'
thisform.ListBox.RowSourceType = 2
IF !USED('Table2')
thisform.ListBox.SetFocus()
FOR ncnt = 1 TO thisform.ListBox.ListCount
chkfield = PADL(ALLTRIM(STR(nCnt)),2,'0') + '_c'
IF !EMPTY(Table1.fieldname&chkfield)
lst = VAL(ALLTRIM(Table1.fieldname&chkfield))
thisform.ListBox.Selected(lst) = .T.
ENDIF
ENDFOR
ELSE
SELECT Table2
SCAN
thisform.ListBox.SetFocus()
FOR nCnt = 1 TO THISFORM.ListBox.ListCount
IF Table2.fieldname = THISFORM.ListBox.List(nCnt,1)
thisform.ListBox.Selected(nCnt) = .T.
ENDIF
ENDFOR
ENDSCAN
ENDIF
RETURN
I'm not discounting the idea that the class for the form may be causing issues, but I'm not catching anything from the debugger. I don't see it going through class code after it runs this function. Would any of you lovely people have any suggestions??