April 25, 2024, 01:35:55 AM

News:

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


Find Selected Item in ListView

Started by LarryMc, September 23, 2011, 04:40:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

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



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

billhsln

Tried to find Fletchie's CTL lib, it does not seem to be available any where.  Is there doc to go with it?

Bill
When all else fails, get a bigger hammer.

LarryMc

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

billhsln

September 23, 2011, 09:41:34 PM #3 Last Edit: September 23, 2011, 09:45:42 PM by billhsln
Downloaded file, tried to run, but it is looking for IBasic Pro (uninstalled years ago).

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

Would you like to know how to make it work?  ;D ;D ;D ;D ;D ;D

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

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
When all else fails, get a bigger hammer.