RE: SetIndex - List View

new topic     » topic index » view thread      » older message » newer message

> From: "Tony Steward" <figjam at nlc.net.au>
> > Hi all,
> > I have a need to setIndex in a listview but this is of 
> cause not supported.
> > Does anyone have any ideas.
> > 
> > What I am trying to achieve is to have a listview with a 
> textEditBox box
> > below it, where I can type and the listview automatically 
> scrolls to the
> > nearest match. I have already achieved this with a normal 
> List, so setting
> > the index is what I need help with.

> From: Euman [mailto:euman at bellsouth.net]

> Tony this isnt tested, try it out and see if it works. If it 
> doesnt then
> play around with it some....
> 
> VOID=sendMessage(id,LVM_SETITEMPOSITION,OLD_INDEX,LVM_SETITEMPOSITION)

This would actually change the position of the item relative to the other
items in the list.  There's no one-liner (that I'm aware of) that will do
this for you.  Part of the issue is that you have to do a conversion between
win32lib id for each item (stored as the lParam member of the listview item)
and the iItem (which identifies the item by order in the list).  The
following should give the same functionality as setIndex does for lists
(Derek, this would make a good 'Dispatch' for setItem in the listview file):

-- this function should be in .56, although the name will be different
global function getLViItemFromlParam( integer id, integer lv_id )
    atom findlv, item

    findlv = struct_LVFINDINFO( LVFI_PARAM, "", lv_id, 0, 0, 0 )
    item = sendMessage( id, LVM_FINDITEM, -1, findlv )
    release_mem( findlv )

    return item
end function 

-- Can set multiple selections, and first item will be made visible
procedure setLVIndex( integer id, object sel )
    integer iItem
    atom lvitem
    if atom(sel) then
        sel = {sel}
    end if
    lvitem = struct_LVITEM( LVIF_STATE, 0, 0, LVIS_SELECTED, LVIS_SELECTED,
0,0,0)
    for i = length( sel ) to 1 by -1 do
        iItem = getLViItemFromlParam( id, sel[i] )
        store( lvitem, LVITEM_iItem, iItem )
        VOID = sendMessage( id, LVM_SETITEMSTATE, iItem, lvitem )
    end for
    VOID = sendMessage( id, LVM_ENSUREVISIBLE, iItem, 0 )
end procedure


Matt Lewis

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu