Re: ListView item addressing
- Posted by Greg Haberek <ghaberek at gmail.com> Jan 14, 2006
- 530 views
> 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 )