Changing values in a list view column

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

To anyone interested...

The included code snippet lets you do in-place editing of a list view 
column's contents.  To change the contents, click ONCE on the first 
column of each list view item.  Wait a second and then an edit control 
should appear.  Type in some text and press Enter.  The column data is 
updated.  There is a button on the bottom that SHOULD start editing of a 
column but it doesn't work :(

Anyway, has anyone else ever tried this?  Is there any way to change the 
contents of columns other than the first?  How do I force editing of 
another column/row with the LVM_EDITLABLE message?  I guess what I'm 
wondering is if you can, with a list view control, come up with a 
primitive grid control?  

Jonas

Here is the code!  

include win32lib.ew
without warning
with trace
atom void
global constant MainWin = create(Window, "Test Editable List Views", 0, 
0, 0, 500, 400, 0),
                lv = create(ListView, {"Column1","Column2","Column3"}, 
MainWin, 10, 10, 400, 300,
                            or_all({LVS_REPORT,LVS_EDITLABELS})),
                pb = create( PushButton, "Test", MainWin, 10, 350, 90, 
30, 0)

procedure MainWin_onEvent(atom event, atom wParam, atom lParam)
    atom edit_ctl, iLength, buffer, id, msg
    sequence text, selection
    if event = WM_NOTIFY then
        id = getId( fetch( lParam, NMHDR_hwndFrom ))
        msg = fetch( lParam, NMHDR_code )
        if id = lv and (msg = LVN_ENDLABELEDITW or msg = 
LVN_ENDLABELEDITA) then
            edit_ctl = sendMessage(lv, LVM_GETEDITCONTROL, 0, 0)
            if edit_ctl then
                iLength = w32Func( xSendMessage, { edit_ctl, 
WM_GETTEXTLENGTH, 0, 0 } )
                if iLength > 0 then
                  iLength += 1
                  buffer = acquire_mem(0, iLength )
                  iLength = w32Func( xSendMessage, { edit_ctl, 
WM_GETTEXT, iLength, buffer } )
                  text = peek( {buffer, iLength} )
                  release_mem( buffer )
                  selection = getLVSelected(lv)
                  setLVItemText(lv, selection[1], 0, text)
                end if
            end if
        end if
    end if
end procedure
onEvent[MainWin] = routine_id("MainWin_onEvent")

procedure MainWin_onOpen()
    atom index, mask, void
    sequence data
	mask = or_all({LVS_EX_HEADERDRAGDROP,LVS_EX_GRIDLINES,
	LVS_EX_TRACKSELECT })
	void = sendMessage(lv, LVM_SETEXTENDEDLISTVIEWSTYLE, mask, mask)

    for i = 1 to 3 do
        data = {"Row" & sprintf("%d", i) & "Col1",
                "Row" & sprintf("%d", i) & "Col2",
                "Row" & sprintf("%d", i) & "Col3"}
        index = addLVItem(lv, 0, data)
    end for
end procedure
onOpen[MainWin] = routine_id("MainWin_onOpen")

procedure pb_onClick()
    sequence selection
    atom void
    selection = getLVSelected(lv)
    void = sendMessage(lv, LVM_EDITLABEL, 1, 0)
end procedure
onClick[pb] = routine_id("pb_onClick")


WinMain(MainWin, Normal)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu