May 10, 2024, 11:39:09 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Listbox item positon

Started by aurelCB, September 10, 2010, 06:05:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi ...
I find that i have very weird problem with listbox.
I simply want recive position of selected item from listbox when i click or doubleclick
one item.
Here is code which constantly return -1 as position ,i read help twice... ???
'the listbox program
DEF w1:window
DEF pos:int
'open a window and add a menu
OPENWINDOW w1,0,0,600,400,@SIZE|@MINBOX|@MAXBOX|@CAPTION,0,"Lines",&mainwindow
SETWINDOWCOLOR w1,RGB(220,220,230)

CONTROL w1,@LISTBOX,"",4,60,160,150,0x50B00140,3
'add items
AddString w1,3,"0.item"
AddString w1,3,"1.item"
AddString w1,3,"2.item"
AddString w1,3,"3.item"
AddString w1,3,"4.item"
AddString w1,3,"5.item"
AddString w1,3,"6.item"


waituntil w1 = 0
end

SUB mainwindow
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
CASE @IDCONTROL
'.......................................
IF @CONTROLID=3
'F @NOTIFYCODE=0
'---------------------------------
pos=GETSELECTED(w1,3)
Move w1,10,10:Print w1,"POS:",str$(pos)
'---------------------------------
'ENDIF
ENDIF
' also try with ...
CASE @IDLBUTTONDBLCLK
pos=GETSELECTED(w1,3)
Move w1,10,10:Print w1,"POS:",pos

'.........................................
ENDSELECT
RETURN
ENDSUB

LarryMc

September 10, 2010, 06:19:26 AM #1 Last Edit: September 10, 2010, 06:40:24 AM by Larry McCaughn
Aurel

You're missing a style flag

CONTROL w1,@LISTBOX,"",4,60,160,150,0x50B00140|@CTLISTNOTIFY,3
and I changed your handler just a little
SUB mainwindow
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
CASE @IDCONTROL
'.......................................
select @CONTROLID
case 3
select @NOTIFYCODE
case @LBNDBLCLK
case& @LBNSELCHANGE
'---------------------------------
pos=GETSELECTED(w1,3)
Move w1,10,10:Print w1,"POS:",str$(pos)
'---------------------------------
endselect
ENDselect
'.........................................
ENDSELECT
RETURN
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

September 10, 2010, 07:15:03 AM #2 Last Edit: September 10, 2010, 07:26:06 AM by aurelCB
Oh my...
I feel that something missing ::)
Thank you Larry..again

I miss this from help:
Quote@CTLISTNOTIFY
Parent window receives an input message whenever the user clicks or double-clicks a string

I get that same program work with ENTER key:
'the listbox program
DEF w1:window
DEF pos:uint
'open a window and add a menu
OPENWINDOW w1,0,0,600,400,@SIZE|@MINBOX|@MAXBOX|@CAPTION,0,"Lines",&mainwindow
SETWINDOWCOLOR w1,RGB(220,220,230):BACKPEN w1,RGB(220,220,230)
Move w1,100,10:Print w1,"Select item then press ENTER..."
CONTROL w1,@LISTBOX,"",4,60,160,150,0x50B00140,3
SETCONTROLNOTIFY w1,3, TRUE, TRUE
'add items
AddString w1,3,"0.item"
AddString w1,3,"1.item"
AddString w1,3,"2.item"
AddString w1,3,"3.item"
AddString w1,3,"4.item"
AddString w1,3,"5.item"
AddString w1,3,"6.item"


waituntil w1 = 0
end

SUB mainwindow
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
CASE @IDCONTROL
'.......................................
IF @CONTROLID=3
IF @NOTIFYCODE=@ENENTERKEY
'---------------------------------
pos=GETSELECTED(w1,3)
Move w1,10,10:Print w1,"POS:",str$(pos)
'---------------------------------
ENDIF
ENDIF

'.........................................
ENDSELECT
RETURN
ENDSUB


But your option is far better ;)

Why i need this...
I want use this in first place in ABasic left side listbox to
highlite line in scintilla control.
So if user load code with many subs then when doublclick sub name in listbox
scintilla automaticly go to line where is this sub located...

And works on this way :
IF @CONTROLID=3
IF @NOTIFYCODE=@LBNDBLCLK
'---------------------------------
pos=GETSELECTED(w1,3)
Move w1,10,10:Print w1,"POS:",str$(pos)
'---------------------------------
ENDIF
ENDIF


Thanks ... :)

Aurel

LarryMc

I use a combox to do that in my current Visual Designer.  In VD2 I will use a listview to do the same thing except it will contain ALL the subs in the entire project will be available.

Glad I could help you a little.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library