Listbox items

Moderator: Rathinagiri

Post Reply
bluebird
Posts: 167
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF
Has thanked: 49 times
Been thanked: 7 times

Listbox items

Post by bluebird » Mon Jan 16, 2017 8:16 pm

The listbox control below has an items array literally declared within. A function to return the value was also written as shown.

1.)
Can that items entry be an array variable, example
aTypes :={"Financial","Commercial","Technical","Entertainment"}
.
.
.

ITEMS aTypes

If so, can the same listbox be invoked and re-used with different arrays, each containing other items lists?

2) If you want to select an "item", do you have to write a function like I did to fetch the selection so that it can be
displayed elsewhere?

DEFINE LISTBOX L_Type
ROW 73
COL 70
PARENT Form_2
WIDTH 200
HEIGHT 35
VALUE 0
VISIBLE .F.
ON LOSTFOCUS GetcType()
ITEMS {"Financial","Commercial","Technical","Entertainment"}
END LISTBOX

*-----------------------------------------------------
Function GetcType()
*-----------------------------------------------------
Local nTypeIndex:=0, cTypex

form_2.L_Type.visible:=.F. //hide the listbox after using it
form_2.T_Type.visible:=.T. //show the textbox with the value over top of hidden listbox

nTypeIndex:=Form_2.L_type.value // get litbox index to "items"
cTypex:=aTypes[nTypeIndex] // find out its value from a LOCAL array that has the same values as the ListBox
form_2.T_Type.Value:=cTypex // display the selected "Item"

return

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Mon Jan 16, 2017 9:33 pm

Sorry, I did not understand it...

Would you make a practical example to make easier the test ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Rathinagiri
Posts: 5264
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Tue Jan 17, 2017 3:21 am

bluebird wrote:
Mon Jan 16, 2017 8:16 pm
1.)Can that items entry be an array variable, example
aTypes :={"Financial","Commercial","Technical","Entertainment"}
.
.
.

ITEMS aTypes

If so, can the same listbox be invoked and re-used with different arrays, each containing other items lists?
Yes! You can use any array of items to an existing listbox.

For that you need to write coding for adding the array items. It can be done in a small function also. For example,

Code: Select all

aMyArray := { 'Item1', 'Item2', 'Item3' }
myform.mylistbox.deleteallitems
for i := 1 to len( aMyArray )
   myform.mylistbox.additem( aMyArray[ i ] )
next i
Or

Code: Select all

aMyArray := { 'Item1', 'Item2', 'Item3' }
Set_Array_to_ListBox( 'myform', 'mylistbox', aMyArray )

function Set_Array_to_ListBox( cFormName, cListBox, aArray )
   local i
   doMethod( cFormName, cListBox, 'DELETEALLITEMS' )
   for i := 1 to len( aArray )
      doMethod( cFormName, cListBox, 'ADDITEM', aArray[ i ] )
   next i
return nil
bluebird wrote:
Mon Jan 16, 2017 8:16 pm
2) If you want to select an "item", do you have to write a function like I did to fetch the selection so that it can be
displayed elsewhere?

DEFINE LISTBOX L_Type
ROW 73
COL 70
PARENT Form_2
WIDTH 200
HEIGHT 35
VALUE 0
VISIBLE .F.
ON LOSTFOCUS GetcType()
ITEMS {"Financial","Commercial","Technical","Entertainment"}
END LISTBOX

*-----------------------------------------------------
Function GetcType()
*-----------------------------------------------------
Local nTypeIndex:=0, cTypex

form_2.L_Type.visible:=.F. //hide the listbox after using it
form_2.T_Type.visible:=.T. //show the textbox with the value over top of hidden listbox

nTypeIndex:=Form_2.L_type.value // get litbox index to "items"
cTypex:=aTypes[nTypeIndex] // find out its value from a LOCAL array that has the same values as the ListBox
form_2.T_Type.Value:=cTypex // display the selected "Item"

return
No. Need not be!

Code: Select all

Function GetcType()
form_2.L_Type.visible:=.F.   //hide the listbox after using it
form_2.T_Type.visible:=.T.  //show the textbox with the value over top of hidden listbox
form_2.T_Type.Value:=form_2.l_type.item( form2.l_type.value )        // display the selected "Item"
return
The above code is enough. All the items from a listbox can at any time be retrieved using formname.listbox.item( nItemIndex )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply