August 22, 2019, 12:35:22 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


List view selected position

Started by Andy, November 10, 2018, 05:44:10 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

November 10, 2018, 05:44:10 am Last Edit: November 10, 2018, 05:46:58 am by Andy
I'm using this code (and many of you have also used it) to get the selected item in a list view....

Code Select
LVpos=*<NMLISTVIEW>@LPARAM.iItem


But when I place it in the @TIMER section of my window's handler it crashes the program.

How can I tell NMLISTVIEW to "look" at (or point to) the correct list view control, here it's simply called "ListView", or am I missing something.

Any ideas any one?

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

November 10, 2018, 11:56:04 am #1 Last Edit: November 10, 2018, 12:12:37 pm by fasecero
No, NMLISTVIEW is a system structure used in some listview notifications, only in these cases you can use it. I think Larry can explain better how this works. @LPARAM points towards something different for each message, you should always have to check at the help file. I don't know what content @LPARAM can provide in @IDTIMER, but it will certainly not point to a listview structure.

You can use that in @LVNITEMCHANGED notification, from the help file

QuoteNotification messages
A list view control sends notification messages to the parent window or dialog in the @NOTIFYCODE variable. The ID of the control is found in @CONTROLID the same as standard controls. The following notification messages are supported:
...
@LVNITEMCHANGED
Indicates that an item has changed.
@QUAL contains a memory handle to a NMLISTVIEW data type.
...
Some notification messages set @LPARAM to a UDT pointer.


Then, after looking at MSDN how NMLISTVIEW looks like (usually this is not enough and you have to look elsewhere to see how to use it), and knowing that you want to process the selection bit you will end up with something like this... I made up an example...

Code Select

$INCLUDE "windowssdk.inc"
$INCLUDE "Commctrl.inc"

CONST LISTVIEW_1 = 1
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
CONTROL w1,@LISTVIEW,"",62,32,421,279,0x50800000,LISTVIEW_1

INT h
FOR h = 1 TO 5
CONTROLCMD w1, LISTVIEW_1, @LVINSERTITEM, h - 1, "Item #" + STR$(h)
NEXT h

' main loop
WAITUNTIL w1 = 0
END

' window procedure
SUB w1_handler(), INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1

CASE @IDCLOSEWINDOW
CLOSEWINDOW w1

CASE @IDCONTROL
SELECT @CONTROLID
CASE LISTVIEW_1
SELECT @NOTIFYCODE
CASE @LVNITEMCHANGED
IF *<NMLISTVIEW>@LPARAM.uNewState & LVIS_SELECTED THEN
INT sel_item = *<NMLISTVIEW>@LPARAM.iItem + 1
SETCAPTION w1, "Item #" + LTRIM$(STR$(sel_item)) + " was selected"
ENDIF
ENDSELECT
ENDSELECT

ENDSELECT

RETURN 0
ENDSUB


fasecero

Just in case I know that all that info doesn't help to solve you issue. I was just trying to maybe help you to understand your mistake. This would be a dirty way to get the selected item inside a timer.

Code Select

$INCLUDE "windowssdk.inc"
$INCLUDE "Commctrl.inc"

CONST LISTVIEW_1 = 1
CONST TIMER_2 = 2
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
CONTROL w1,@LISTVIEW,"",62,32,421,279,@LVSICON|@BORDER|@LVSSHOWSELALWAYS|@LVSSINGLESEL|@VSCROLL,LISTVIEW_1

INT h
FOR h = 1 TO 5
CONTROLCMD w1, LISTVIEW_1, @LVINSERTITEM, h - 1, "Item #" + STR$(h)
NEXT h

' main loop
WAITUNTIL w1 = 0
END

' window procedure
SUB w1_handler(), INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
STARTTIMER w1, 1000, TIMER_2

CASE @IDCLOSEWINDOW
STOPTIMER w1, TIMER_2
CLOSEWINDOW w1

CASE @IDTIMER
SELECT @WPARAM
CASE TIMER_2
INT position = LisviewGetSelectedItem(w1, LISTVIEW_1)

IF position THEN
SETCAPTION w1, "Item #" + LTRIM$(STR$(position)) + " was selected"
ELSE
SETCAPTION w1, "No item selected"
ENDIF
ENDSELECT
ENDSELECT

RETURN 0
ENDSUB

SUB LisviewGetSelectedItem(WINDOW w, INT listviewID), INT
INT count = CONTROLCMD(w, listviewID, @LVGETCOUNT)

INT j
FOR j = 1 TO count
IF CONTROLCMD(w1, listviewID, @LVGETSELECTED, j - 1) THEN RETURN j
NEXT j

RETURN 0
ENDSUB


I hope it helps :)

Andy

Thanks Fasecero,

I get the mistake now - thanks for pointing it out to me!

I will let you know how the time code goes - thanks.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.