Hi all...
As i say in title i have problem with listview @LVgetselected.
In help is written this:
Quoteselected = CONTROLCMD( window | dialog, ID, @LVGETSELECTED, item)
Use this function to determine the selected state of the item.
item is the zero-based index of the item.
I use for test Listview example and as result i recive weird things.
When i select first item and clik button i recive result 2.
When i select second item and clik button i recive result 0.
 ???
How is that posible?
Or what i do wrong?
here is code:
'This is a simple list view demo. The list view is created in report mode
'and two columns are added.
'requires EBASIC 1.0 or greater
'Compile as a WINDOWS target
def d1:Dialog
def str:STRING
def p as pointer
int lvitem
int getselecteditem
string text
'standard NMLISTVIEW
'when a column ic clicked on Windows sends a variable
'of this type in @LPARAM. 
TYPE NMLISTVIEW
	def hwndFrom:UINT
	def idFrom:INT
	def code:INT
    def iItem:INT 
    def iSubItem:INT 
    def uNewState:UINT 
    def uOldState:UINT 
    def uChanged:UINT 
    def ptActionx:INT
	def ptActiony:INT 
    def lParam:INT 
ENDTYPE
CREATEDIALOG d1,0,0,405,368,0x80C80080,0,"List view test",&handler
CONTROL d1,@LISTVIEW,"",27,24,240,110,0x50000001,1
CONTROL d1,@STATIC,"TEST",27,140,240,20,0x50000000,2
CONTROL d1,@BUTTON,"Button1",54,235,70,20,0x50000000,3
domodal d1
end
SUB handler
select @MESSAGE
	case @IDINITDIALOG
		centerwindow d1
		'insert columns and some items
		'after an item is inserted we use @LVSETTEXT to
		'change the subitems text
		CONTROLCMD d1,1,@LVINSERTCOLUMN,0,"Column1"
		CONTROLCMD d1,1,@LVINSERTCOLUMN,1,"Column2"
		CONTROLCMD d1,1,@LVINSERTITEM,0,"Item 1"
		CONTROLCMD d1,1,@LVSETTEXT,0,1,"Subitem 1"
		CONTROLCMD d1,1,@LVINSERTITEM,1,"Item 2"
		CONTROLCMD d1,1,@LVSETTEXT,1,1,"Subitem 2"
	case @IDCONTROL
		if(@CONTROLID = 1)
			'someone clicked on a column header. Read the data from @LPARAM which is 
			' a pointer to a NMLISTVIEW UDT. Using the C dereferencing style makes
			' it much easier
			
			if(@NOTIFYCODE = @LVNCOLUMNCLICK)
				'CONTROLCMD d1,1,@LVSETCOLUMNTEXT,*<NMLISTVIEW>@LPARAM.iSubItem,"Clicked!"
				
			endif
		ENDIF
		if @CONTROLID = 3
		getselecteditem=CONTROLCMD( d1, 1, @LVGETSELECTED, lvitem)
			'CONTROLCMD d1, 1, @LVSETSELECTED,getselecteditem
			MESSAGEBOX 0,"SELECTED:"+str$(getselecteditem),"TEST"
			CONTROLCMD(d1,1, @LVGETTEXT, lvitem,1, text)
			MESSAGEBOX 0,"SELECTED_IS:"+text,"TEST"
		ENDIF
endselect
return
ENDSUB
			
				CONTROLCMD @LVGETSELECTED is a wrapper for SendMessage+LVM_GETITEMSTATE which returns a set of LVIS_*** flags for the specified item (by index).
The selected state bit is LVIS_SELECTED = 2.
With CONTROLCMD+@LVGETSELECTED you can check if a item is selected or not.
If you want to enumerate selected items, include windowssdk.inc and commctrl.inc, and then:
HWND hwndList = GETCONTROLHANDLE( ... )
int itemIndex = SendMessageA(hwndList, LVM_GETNEXTITEM, -1, LVNI_SELECTED)
while (itemIndex >= 0)
	' item 'itemIndex' is selected
	itemIndex = SendMessageA(hwndList, LVM_GETNEXTITEM, itemIndex, LVNI_SELECTED)
wend
			
			
			
				Aurel
Try my version
LarryMc
'This is a simple list view demo. The list view is created in report mode
'and two columns are added.
'requires EBASIC 1.0 or greater
'Compile as a WINDOWS target
def d1:Dialog
def str:STRING
def p as pointer
int lvitem
int getselecteditem
string text
'standard NMLISTVIEW
'when a column ic clicked on Windows sends a variable
'of this type in @LPARAM. 
TYPE NMLISTVIEW
	def hwndFrom:UINT
	def idFrom:INT
	def code:INT
    def iItem:INT 
    def iSubItem:INT 
    def uNewState:UINT 
    def uOldState:UINT 
    def uChanged:UINT 
    def ptActionx:INT
	def ptActiony:INT 
    def lParam:INT 
ENDTYPE
CREATEDIALOG d1,0,0,405,368,0x80C80080,0,"List view test",&handler
CONTROL d1,@LISTVIEW,"",27,24,240,110,0x50000001,1
CONTROL d1,@STATIC,"TEST",27,140,240,20,0x50000000,2
CONTROL d1,@BUTTON,"Button1",54,235,70,20,0x50000000,3
domodal d1
end
SUB handler
select @MESSAGE
	case @IDINITDIALOG
		centerwindow d1
		'insert columns and some items
		'after an item is inserted we use @LVSETTEXT to
		'change the subitems text
		CONTROLCMD d1,1,@LVINSERTCOLUMN,0,"Column1"
		CONTROLCMD d1,1,@LVINSERTCOLUMN,1,"Column2"
		CONTROLCMD d1,1,@LVINSERTITEM,0,"Item 1"
		CONTROLCMD d1,1,@LVSETTEXT,0,1,"Subitem 1"
		CONTROLCMD d1,1,@LVINSERTITEM,1,"Item 2"
		CONTROLCMD d1,1,@LVSETTEXT,1,1,"Subitem 2"
	case @IDCONTROL
		if(@CONTROLID = 1)
			'someone clicked on a column header. Read the data from @LPARAM which is 
			' a pointer to a NMLISTVIEW UDT. Using the C dereferencing style makes
			' it much easier
			
			if(@NOTIFYCODE = @LVNCOLUMNCLICK)
				'CONTROLCMD d1,1,@LVSETCOLUMNTEXT,*<NMLISTVIEW>@LPARAM.iSubItem,"Clicked!"
				
			endif
		ENDIF
		if @CONTROLID = 3
			int x
				for x= 0 to (CONTROLCMD(d1,1, @LVGETCOUNT)-1)
					if CONTROLCMD(d1,1, @LVGETSELECTED, x)
						CONTROLCMD(d1,1, @LVGETTEXT, x,1, text)
						MESSAGEBOX d1,"SELECTED_IS:"+text,"Row"+str$(x)+" (0 based)"
					endif
				next x
		ENDIF
endselect
return
ENDSUB
			
			
			
				Thank you guys!
I think that i must use counter but i need this in first place bacose i want implement this 
in ABasic .Hmmm im still not sure what to use ....
I will see ...
thanks again...
all best 
Aurel
			
			
			
				Sapero's code goes through only those items that are selected.
My example goes through all items and checks to see which ones are selected.
Therefore Sapero's way is the fastest.
LarryMc
			
			
			
				Yes Larry ,Sapero way is faster for sure but your is simplier for me .
I also found one Wayne example which use similiar method.
Here is piece of code how i store listview item in LinkedList in ABasic and work fine...
IF CONTROLEXISTS(w2,cID)
		count=ControlCMD(w2,cID,@LVGetCount)
		For lvitem = 0 to count
			IF ControlCMD(w2,cID,@LVGetSelected,lvitem)
				getselecteditem = lvitem
				BREAKFOR
			ENDIF
		Next lvitem
		'store lvitem in LList
		error=1
		PosInList = ListGetFirst(intList)
		WHILE (PosInList <> 0) 
			intVar = ListGetData(PosInList)
			IF #intVar.intName = GW3
				#intVar.intValue = getselecteditem
				error=0
			ENDIF
			PosInList = ListGetNext(PosInList)
		ENDWHILE
			
			
			
				Aurel
In your last example you need to get rid of the BREAKFOR statement.
With it in there you will only find a max of 1 selected items.
LarryMc
			
			
			
				No Larry it work as espected.
I have two commands for this :
button sub is:
SUBID 110
GetLVselected lvID selected
GetLVText lvID selected 1 g$
Print 20 220 "                                                                "
Print 20 220 g$
ENDSUB 
And work ok..
by the way you can download lates release and try example Listview1.aon in ABasic.
http://aurelbasicsoft.ucoz.com/ABasic1v0.zip
			
			
			
				form the help file
QuoteBREAKFOR allows an early exit of a FOR/NEXT loop before the loop has finished all of the iterations.
from your posted code:
		count=ControlCMD(w2,cID,@LVGetCount)
		For lvitem = 0 to count
			IF ControlCMD(w2,cID,@LVGetSelected,lvitem)
				getselecteditem = lvitem
				BREAKFOR
			ENDIF
		Next lvitem
'<== BREAKFOR continues hereif count is 1000 and all are selected, the FOR loop will be exited while the ivitem=0 and will never check the rest of the selected items.
The only way your posted code will work correctly is if you limit selections to 1 at a time by the user.
to make your code work for multiple selections you would need to replace the BREAKFOR with a call to subroutine that adds the selection to your linked lists.
LarryMc
			
				Yeah ...you right , im limit selection to 1.
I will remeber what you say ,good point  ;)