1. ListView item addressing

Using the win32lib I learn that:

".. each item in a list view has a unique ID number.. no two listview items have
the same ID value, regardless of which listview it they are in. The item ID is
not the same as its index value. The index value is where in a list view the item
is positioned. The ID is used as a way to identify an item without referring to
its column values or position. When you add an item using addLVItem, you get the
item's ID returned."

This seems quite clear, but I cannot find any other reference to this ID
parameter: all the described ListView routines seem to make use or refer to the
row number only.

Somebody knows a direct mode to access or update a value into a ListView when
the rows order has been changed?

new topic     » topic index » view message » categorize

2. Re: ListView item addressing

Antonio Alessi wrote:
> 
> Using the win32lib I learn that:
> 
> ".. each item in a list view has a unique ID number.. no two listview items
> have the same ID value, regardless of which listview it they are in. The item
> ID is not the same as its index value. The index value is where in a list view
> the item is positioned. The ID is used as a way to identify an item without
> referring to its column values or position. When you add an item using
> addLVItem,
> you get the item's ID returned."
> 
> This seems quite clear, but I cannot find any other reference to this ID
> parameter:
> all the described ListView routines seem to make use or refer to the row
> number
> only. 
> 
> Somebody knows a direct mode to access or update a value into a ListView when
> the rows order has been changed?

I believe that whenever refering to a ListView item, you should use the
item number.  There are many routines in Win32Lib that can be used for
many different control types, and most of the others (ListBox, ComboBox, etc)
use the position of the item.  Most of those routines predate the addition
of ListViews to Win32Lib.

Windows treats ListViews differently, however, and therefore so does
Win32Lib.  Part of the reason is that ListView items can contain more
information than the simple text that a ListBox has (you have columns,
checkboxes, icons and other user defined data).

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: ListView item addressing

Thanks for your kind answer Matt, however it does not seem to resolve any
question.
It coultra be needed to update any record in a LView after one or more sort
changes.

I can write various routines that help indirectly the use of the row indexes,
but these look somehow "primitive" and complicated ways since every ID exist and
then it should be accessible; therefore I don't understand the reason of all that
introduction to the ListView funtions if those ID are not available for use.

Regards,
Antonio Alessi

new topic     » goto parent     » topic index » view message » categorize

4. Re: ListView item addressing

Antonio Alessi wrote:
> 
> Using the win32lib I learn that:
> 
> ".. each item in a list view has a unique ID number.. no two listview items
> have the same ID value, regardless of which listview it they are in. The item
> ID is not the same as its index value. The index value is where in a list view
> the item is positioned. The ID is used as a way to identify an item without
> referring to its column values or position. When you add an item using
> addLVItem,
> you get the item's ID returned."
> 
> This seems quite clear, but I cannot find any other reference to this ID
> parameter:
> all the described ListView routines seem to make use or refer to the row
> number
> only. 
> 
> Somebody knows a direct mode to access or update a value into a ListView when
> the rows order has been changed?

Do these unique ID numbers change when you resort?

Don Cole
 A Bug is an un-documented feature.
A Feature is a documented Bug.

new topic     » goto parent     » topic index » view message » categorize

5. Re: ListView item addressing

Hi Don,

what I have understood is that the ID should be, or should behave, like a
handle, so there is no reason for this to change once set.
If this is true, it should be esasy to refer [commands] to every record by one
unique ID, no matter which is its rows index.

I cannot definitely verify this, in lack of a documented way to check [and use]
an item's ID, after created it by addLVItem( ).

Antonio Alessi

new topic     » goto parent     » topic index » view message » categorize

6. Re: ListView item addressing

Antonio Alessi wrote:
> 
> Using the win32lib I learn that:
> 
> ".. each item in a list view has a unique ID number.. no two listview items
> have the same ID value, regardless of which listview it they are in. The item
> ID is not the same as its index value. The index value is where in a list view
> the item is positioned. The ID is used as a way to identify an item without
> referring to its column values or position. When you add an item using
> addLVItem,
> you get the item's ID returned."
> 
> This seems quite clear, but I cannot find any other reference to this ID
> parameter:
> all the described ListView routines seem to make use or refer to the row
> number
> only. 
> 
> Somebody knows a direct mode to access or update a value into a ListView when
> the rows order has been changed?

I see what you saying,

 idx=addLVItem (  ID, iIcon, text )

 ID is the id if the ListView.

 idx is a unique ID number.

and you want to access inx without going though colums and row stuff,

by going directly to the unique ID number .   



I'm sorry but I don't know how to do that. smile

Other than keeping an index of all colums and rows in relationship to
idx.
Look up the idx and going to that col and row.


Don Cole
 A Bug is an un-documented feature.
A Feature is a documented Bug.

new topic     » goto parent     » topic index » view message » categorize

7. Re: ListView item addressing

> Other than keeping an index of all colums and rows in relationship to
> idx.
> Look up the idx and going to that col and row.

check out this demo i made, mostly addLVItemEx()

-- this demo shows the difference between an index and an id in a ListView
-- the index is always the number of the row starting from the top, while
-- the id is a unique id to reference the row, no matter how it is sorted
--
-- addLVItemEx() returns {index, id}

include Win32Lib.ew
without warning

constant

    Main = create( Window, "ListView Test", 0, Default, Default, 480, 320=
, 0 ),
    LV = create( ListView, {
                    {"Item Number",120,'<'},
                    {"Index",90,'<'},
                    {"Unique ID",90,'<'}}, Main, 0, 0, 1, 1, LVS_REPORT )

global function addLVItemEx( object id, atom iIcon, sequence text )

    atom iItem
    integer lWhere
    sequence lNewItem

    integer lvInsertWhere
    atom lvitem_MASK

    -- these values are not global in Win32Lib
    lvInsertWhere = setLVInsert( 0 )
    VOID = setLVInsert( lvInsertWhere )

    lvitem_MASK = w32or_all( { LVIF_TEXT, LVIF_IMAGE, LVIF_PARAM} )

    iIcon -= 1
    if sequence(id) then
        lWhere = id[2]
        id = id[1]
    else
        lWhere = lvInsertWhere
    end if


    -- Sanity check
    if not sequence(text) then
        text = sprintf("%g", text)
    end if
    if length(text) = 0 or not sequence(text[1]) then
        text = {text}
    end if

    lNewItem = insertLVItem( id, lvitem_MASK, lWhere, 1,0,0,
                             text[1], iIcon, 0)

    for i = 2 to length(text) do
        setLVItemText( id, lNewItem[1], i, text[i])
    end for

    return lNewItem
end function


constant LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

procedure Main_Open( integer pSelf, integer pEvent, sequence pParams )

    object handle

    for i = 1 to 26 do
        handle = addLVItemEx( LV, -1, {sprintf("Item %s", LETTERS[i]), 0,=
 0} )
        setLVItemText( LV, handle[1], 2, sprintf("%02d", handle[1]) )
        setLVItemText( LV, handle[1], 3, sprintf("%02d", handle[2]) )
    end for

end procedure
setHandler( Main, w32HOpen, routine_id("Main_Open") )

procedure Main_Resize( integer pSelf, integer pEvent, sequence pParams )

    setRect( LV, {w32Edge,4}, {w32Edge,4}, {w32Edge,-4}, {w32Edge,-4}, w32T=
rue )

end procedure
setHandler( Main, w32HResize, routine_id("Main_Resize") )

function LV_Sort( integer ID, integer ItemA, integer ItemB, integer Column =
)

    sequence TextA, TextB

    if ItemA = -1 and ItemB = -1 then

        if Column = w32LV_StartSorting then
            return w32True

        elsif Column = w32LV_EndSorting then
            -- done sorting, rename the second column with the index value

            for i = 1 to getLVCount( LV ) do
                setLVItemText( LV, i, 2, sprintf("%02d", i) )
            end for

            return w32True

        end if

    end if

    TextA = getLVItemText( ID, ItemA, Column )
    TextB = getLVItemText( ID, ItemB, Column )

    return compare( TextA, TextB )
end function
VOID = setLVAttr( LV, {{kLVSortRtn, repeat(routine_id("LV_Sort"),3)}} )

WinMain( Main, Normal )


new topic     » goto parent     » topic index » view message » categorize

8. Re: ListView item addressing

Hi Greg,

thank you for your demo.

I use the Win32lib ver. 59 and cannot run this routine, but it seems to show
very well what I mean.

However I have read it and again not found the answer to my firts question: you
show the relationship of the row-index and ID, as I said, but do not direcltly
write any row [after sorting] using the ID as a pointer instead of the index; is
it?

As I said, I could write various procedures to resolve this, according to the
nature of the problem, but they seem to me redundant if this could be faced in a
much more simple mode.

Anyway I adopted a different solution for my case.

Antonio Alessi

When you understand Euphoria, it's like to fly :ยท

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu