April 24, 2024, 11:30:05 AM

News:

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


listbox not returning the row clicked on

Started by arono, January 21, 2017, 12:27:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

arono

Hello,

I have created a couple of programs that use listboxes and they work correctly.  When I click on an entry, my logic receives the line number that was clicked. 

I am developing another program that has a listbox and for whatever reason the line number that was clicked is not what is returned.  I always get a value of -1.   So I created a stripped-down test version of the program (see attached) that contains all of the code needed to operate the listbox.  It demonstrates the problem nicely.  Note: the label "loopit" and the statement "GOTO loopit" were added for the next bit of testing.

I created a loop around the code that does the WAITUNTIL and discovered that the first time I click on a line (for example: line 2), it returns -1.  Then I clicked on the same line again and it returned the correct line number (2).  After those two clicks, I clicked on line 3 and received the previous line number returned (2).  Then I clicked again on line 3 and got the correct line number (3).  The logic consistently returning the correct line number when I click on the row twice.

Is this an initialization problem or something else?

Thanks for any replies.

billhsln

January 21, 2017, 09:58:21 PM #1 Last Edit: January 22, 2017, 12:04:08 AM by billhsln
Changed the control line to setup the list box:

CONTROL w,@LISTBOX,"My Listbox",700,300,400,310,@CTLISTNOTIFY,ListboxID

Works on Win 10 Pro using IWB 3.0 to compile.

Bill
When all else fails, get a bigger hammer.

arono

Thanks Bill,

Putting the @CTLISTNOTIFY in the style flags section of the Control command worked!!  I suppose that is where all styles belong, however, my other programs with listboxes had  the @CTLISTNOTIFY with the @LISTBOX and any others in the styles section.  Don't remember where I got that idea from.  Anyway, I'll remember to do it your way from now on.

Regarding the problem with the returned listbox row number clicked on by the user was not correct until the user clicked on the same line again.  The purpose of  my listbox is to have the user select a line; the program does some processing while the listbox remains on the screen.  Then the user can click another line in the listbox followed by more processing; etc. etc.

Further experiments found the following to partially work (whereas in other programs of mine I didn't need to do this):

ORIGINAL CODE which received the correct row number every second mouse click:
   LABEL loopit
      rowSelected = -2
      WaitUntil rowSelected > -2
      messagebox w,"row selected = "+str$(rowSelected),""
                ------Do some processing of the line selected.  -------
      goto loopit   ' Allow the user to click on another line.

MODIFIED CODE WHICH ACCOMPLISHES THE SAME THING WITHOUT HAVING THE USER CLICK THE LINE TWICE.  This was done by adding "IF rowSelected < 1 then goto loopit" .  This returned the correct line number, but only once:
   LABEL loopit
      rowSelected = -2
      WaitUntil rowSelected > -2
      IF rowSelected < 1 THEN GOTO loopit
      messagebox w,"row selected = "+str$(rowSelected),"" 
                ------Do some processing of the line selected.  -------
                GOTO loopit  ' Allow the user to click on another line.

With the modified code the second time the user wants to select a line from the listbox, the line has to be clicked twice (back to the original problem). 

This seems to me to be a problem with initializing some internal listbox variable after receiving the correct line number, but I don't know if that's something my program can do.  Perhaps this is how listboxes are supposed to work.   I can solve this problem by issuing a SENDMESSAGE with the parameter LB_RESETCONTENT, then reloading the listbox data.  This method will always return the correct row number with the user clicking on a row once.  This is rather inefficient but quite doable.

Any thoughts on this?

thanks.

billhsln

January 22, 2017, 10:45:13 AM #3 Last Edit: January 22, 2017, 11:38:06 AM by billhsln
Minor Change that might help:

SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEwindow w
END
   CASE @IDCONTROL
SELECT @CONTROLID
IF @NOTIFYCODE = @LBNDBLCLK
case ListboxId
IF @NOTIFYCODE=@LBNSELCHANGE
rowSelected = GETSELECTed(w,ListboxId) + 1
ENDIF
ENDIF
ENDSELECT
ENDSELECT
return 0
ENDSUB


Add in the : IF @NOTIFYCODE=@LBNSELCHANGE
and see if that helps.

Just as a note, with this code, I clicked on each row 2 times and it returned the correct information every time.

Make sure that the value of ListboxId is not used by another control.  Each control must have a unique number assigned to it, the value does not matter, what matters is that you can not have ListboxId = 105 and Static1 as 105, which is why I use the generic ENUM on all.

Also, standard coding would have this logic under the mainw subroutine.

I have a program you might look at: http://www.ionicwind.com/forums/index.php?topic=2273.25
Comes in handy to delete files you don't actually need to keep.  Only delete .opt files if you need to fix how you set it up to be compiled.

Bill
When all else fails, get a bigger hammer.

arono

Thanks Bill again,

I incorporated your IF @NOTIFYCODE=@LBNSELCHANGE change and the GETSELECTED is now returning the correct entry.