IonicWind Software

IWBasic => The Roundtable => Topic started by: LarryMc on September 23, 2011, 04:40:35 PM

Title: Find Selected Item in ListView
Post by: LarryMc on September 23, 2011, 04:40:35 PM
In the past when I've needed to find selected item(s) in a list view I've done it like this:

cnt=CONTROLCMD( w1, LV, @LVGETCOUNT)
if cnt > 0
   for x = 0 to cnt-1
      if CONTROLCMD( w1, LV, @LVGETSELECTED, x) = 1
         'process item
         CONTROLCMD( w1, LV, @LVGETTEXT, x, subitem, text$ )
      endif
   next x
endif

That works fine when you have maybe up to a few hundred items in the list.
But I'm working on a program for my wife where there are over 80,000 entries.
There had to be a better way.
What I wanted was to process a row whenever she double clicked it.
The double click portion is just the standard @notifycode stuff.
What i didn't want was to go through a loop.

Here's my solution:
Const LVM_FIRST  = &H1000
Const LVM_GETSELECTIONMARK  = (LVM_FIRST + 66)
...
case LV
   Select @notifycode
      case @NMDBLCLK
         x= SendMessage(w1 ,LVM_GETSELECTIONMARK, 0, 0, LV)
         'process x
         CONTROLCMD( w1, LV, @LVGETTEXT, x, subitem, text$ )
    endselect


Note, the above code works for single items being selected because it finds the first selected item.

By modifying the code it can be made to work with multiple selections

Const LVM_FIRST  = &H1000
Const LVM_GETSELECTIONMARK  = (LVM_FIRST + 66)
Const LVM_GETNEXTITEM = (LVM_FIRST + 12)
Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)

cnt = SendMessage(w1 ,LVM_GETSELECTEDCOUNT, 0, 0, LV)
if cnt > 0
      cnt--
      x= SendMessage(w1 ,LVM_GETSELECTIONMARK, 0, 0, LV)
      'process x
      CONTROLCMD( w1, LV, @LVGETTEXT, x, subitem, text$ )
      While cnt > 0
         x= SendMessage(w1 ,LVM_GETNEXTITEM, 0, 0, LV)
         if CONTROLCMD(w1 ,LV, @LVGETSELECTED, x) = 1
            'process x
            CONTROLCMD( w1, LV, @LVGETTEXT, x, subitem, text$ )
            cnt--
         endif
      wend
endif


The above will be the fastest when all the selected items are together.  Worse case is when the first and last items are selected.

Also discoverd two functions in Fletchie's CTL lib.

conDrawOff(w1,LV)
' add records to listview
conDrawOn(w1,LV)


While initializing my listview it turns off the updating of the screen.
With the number of records I was adding it cut the time required drastically.

Hope these tips help someone out.

LarryMc



Title: Re: Find Selected Item in ListView
Post by: billhsln on September 23, 2011, 07:17:56 PM
Tried to find Fletchie's CTL lib, it does not seem to be available any where.  Is there doc to go with it?

Bill
Title: Re: Find Selected Item in ListView
Post by: LarryMc on September 23, 2011, 08:47:11 PM
It's available over on my site as a download.

http://www.codingmonkeys.com/index.php?action=tpmod;dl=item108

LarryMc
Title: Re: Find Selected Item in ListView
Post by: billhsln on September 23, 2011, 09:41:34 PM
Downloaded file, tried to run, but it is looking for IBasic Pro (uninstalled years ago).

Thanks,
Bill
Title: Re: Find Selected Item in ListView
Post by: LarryMc on September 23, 2011, 10:29:34 PM
Would you like to know how to make it work?  ;D ;D ;D ;D ;D ;D

LarryMc
Title: Re: Find Selected Item in ListView
Post by: LarryMc on September 23, 2011, 10:43:31 PM
DON"T DO THIS IF YOU STILL HAVE IBPRO INSTALLED AND ARE STILL USING IT!!!!!

Open a text file and copy the following lines into it
Quote[HKEY_CURRENT_USER\Software\Pyxia]

[HKEY_CURRENT_USER\Software\Pyxia\IBasic Pro]

[HKEY_CURRENT_USER\Software\Pyxia\IBasic Pro\PATHS]
"BIN"="C:\\IBWDev\\bin"

Change this line
Quote"BIN"="C:\\IBWDev\\bin"
to the path where you installed IWB

Save-As the file with a .reg extension.

This will make an entry in your registry that the ctl installer is looking for.

right click on the reg file you just created and run as admin.

Now, reinstall the ctlpak.

It should now work.

It worked for me.

LarryMc
Title: Re: Find Selected Item in ListView
Post by: billhsln on September 24, 2011, 07:01:51 AM
I tried the REG file, but must have done some thing wrong.  Ended up putting the entries in manually into RegEdit and then running it.  That seems to have worked.  Will need to see what happens when I load it on my Win7 machine.  This worked on XP.

Too many neat little add on's and utilities.  It must be hard to keep track of all the neat stuff, even with the Snippet Manager.

Thanks,
Bill