Page 1 of 1
Obtaining Selection
Posted: Tue Sep 09, 2008 12:49 am
by esgici
Hi All
Is there a way ( if so sample(s) ) to obtain user's "selected item(s)" from LISTBOX and/or GRID
PS: Without using OnDblClick event.
Regards
--
esgici
Re: Obtaining Selection
Posted: Tue Sep 09, 2008 3:01 am
by Rathinagiri
I think I don't get your point.
Now, we are getting the selected item(s) from the value property of the particular grid. Isn't it?
Re: Obtaining Selection
Posted: Tue Sep 09, 2008 1:48 pm
by esgici
rathinagiri wrote:
Now, we are getting the selected item(s) from the value property of the particular grid. Isn't it?
Hi Rathi
Not quite.
When MULTISELECT is off (default) and VALUE is a single numeric, VALUE property alway updates properly by system while user changes current item into LISTBOX or GRID. In this case we can always obtain user's selection via VALUE property.
When MULTISELECT is on, VALUE property must be a numeric array. In this case user can select single or multiple items into control ( LISTBOX / GRID ) by using almost every selection keystrokes ( up/down keys with shift/ctrl combinations ) and mouse movements (with again shift/ctrl combinations ) except Ctrl-A.
Unfortunately in this second case VALUE array does not update internally by system and we cannot obtain user selection(s).
At least I can't succeed
Regards
--
esgici
Re: Obtaining Selection
Posted: Tue Sep 09, 2008 2:10 pm
by gfilatov
esgici wrote:...
When MULTISELECT is on, VALUE property must be a numeric array. In this case user can select single or multiple items into control ( LISTBOX / GRID ) by using almost every selection keystrokes ( up/down keys with shift/ctrl combinations ) and mouse movements (with again shift/ctrl combinations ) except Ctrl-A.
Unfortunately in this second case VALUE array does not update internally by system and we cannot obtain user selection(s).
At least I can't succeed
Esgici,
Kindly try the following
working sample:
Code: Select all
/*
* Harbour MiniGUI Hello World Demo
* (c) 2002-2004 Roberto Lopez <harbourminigui@gmail.com>
*/
#include "minigui.ch"
Function Main
DEFINE WINDOW Win1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE 'Hello World!' ;
MAIN
DEFINE LISTBOX LIST1
ROW 10
COL 10
WIDTH 100
HEIGHT 110
ITEMS { '01','02','03','04','05','06','07','08','09','10' }
MULTISELECT .T.
END LISTBOX
DEFINE BUTTON BUTTON1
ROW 10
COL 150
CAPTION 'Get Selected Items'
ACTION SelectTest()
WIDTH 150
END BUTTON
END WINDOW
ACTIVATE WINDOW Win1
Return Nil
Procedure SelectTest
local x, n_for, n_pos
local a_result := win1.list1.value
if len( a_result ) == 0
return
end
x := ''
for n_for=1 to len( a_result )
n_pos := a_result[ n_for ]
x += str(n_for) + ": "+ win1.list1.item( n_pos ) + chr(13)
next
msginfo( x , 'Selected item(s): ' + alltrim( str( len( a_result ) ) ) )
Return
Re: Obtaining Selection
Posted: Tue Sep 09, 2008 4:03 pm
by Roberto Lopez
gfilatov wrote:esgici wrote:...
When MULTISELECT is on, VALUE property must be a numeric array. In this case user can select single or multiple items into control ( LISTBOX / GRID ) by using almost every selection keystrokes ( up/down keys with shift/ctrl combinations ) and mouse movements (with again shift/ctrl combinations ) except Ctrl-A.
Unfortunately in this second case VALUE array does not update internally by system and we cannot obtain user selection(s).
At least I can't succeed
Esgici,
Kindly try the following
working sample:
Code: Select all
/*
* Harbour MiniGUI Hello World Demo
* (c) 2002-2004 Roberto Lopez <harbourminigui@gmail.com>
*/
#include "minigui.ch"
Function Main
DEFINE WINDOW Win1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE 'Hello World!' ;
MAIN
DEFINE LISTBOX LIST1
ROW 10
COL 10
WIDTH 100
HEIGHT 110
ITEMS { '01','02','03','04','05','06','07','08','09','10' }
MULTISELECT .T.
END LISTBOX
DEFINE BUTTON BUTTON1
ROW 10
COL 150
CAPTION 'Get Selected Items'
ACTION SelectTest()
WIDTH 150
END BUTTON
END WINDOW
ACTIVATE WINDOW Win1
Return Nil
Procedure SelectTest
local x, n_for, n_pos
local a_result := win1.list1.value
if len( a_result ) == 0
return
end
x := ''
for n_for=1 to len( a_result )
n_pos := a_result[ n_for ]
x += str(n_for) + ": "+ win1.list1.item( n_pos ) + chr(13)
next
msginfo( x , 'Selected item(s): ' + alltrim( str( len( a_result ) ) ) )
Return
Esgici,
This is a very simple and clear sample.
Basically, a multiselect grid 'value' property returns a numeric array containing the positions of selected items.
To obtain the content of a row, you must use the 'item' property using the position as argument.
Remember that 'item' returns an array containing as much elements as columns have the grid.
If you want a specific cell content, you must use the 'cell' property.
ie:
win1.grid1.cell(nRow,nCol)
will give you the content of the cell located at nRow, nCol.
Regards,
Roberto.
Re: Obtaining Selection
Posted: Tue Sep 09, 2008 5:32 pm
by esgici
Thanks Grigory and Roberto
My fault was adding a
VALUE <aValues> statement into LISTBOX/GRID definition
TIA
--
esgici