Obtaining Selection

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
esgici
Posts: 4289
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 174 times
Been thanked: 65 times
Contact:

Obtaining Selection

Post by esgici » Tue Sep 09, 2008 12:49 am

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
Viva INTERNATIONAL HMG :D

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

Post by Rathinagiri » Tue Sep 09, 2008 3:01 am

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?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
esgici
Posts: 4289
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 174 times
Been thanked: 65 times
Contact:

Post by esgici » Tue Sep 09, 2008 1:48 pm

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
Viva INTERNATIONAL HMG :D

User avatar
gfilatov
Posts: 502
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 5 times
Been thanked: 32 times
Contact:

Post by gfilatov » Tue Sep 09, 2008 2:10 pm

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
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
Roberto Lopez
HMG Founder
Posts: 3880
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 107 times

Post by Roberto Lopez » Tue Sep 09, 2008 4:03 pm

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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
esgici
Posts: 4289
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 174 times
Been thanked: 65 times
Contact:

Post by esgici » Tue Sep 09, 2008 5:32 pm

Thanks Grigory and Roberto

My fault was adding a VALUE <aValues> statement into LISTBOX/GRID definition :(

TIA

--

esgici
Viva INTERNATIONAL HMG :D

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests