1. RE: 'F2' to Edit Item in ListView

C.K.,

Attached is some code I posted a while back that let's you edit the 
first column of a list view (note that you can only edit the first 
column in a list view, as Derek pointed out).  I thought it was included 
in win32lib but it's not.  I also added a routine to edit the label when 
F2 is pressed.

HTH, 

Jonas

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}))

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 lv_onKeyDown(integer self, integer event, sequence parms)
    sequence lv_select
    if parms[1] = VK_F2 then
        lv_select = getLVSelected(lv)
        if length(lv_select) then
            void = sendMessage(lv, LVM_EDITLABEL, lv_select[1]-1, 0)
        end if
    end if
end procedure
setHandler( lv, w32HKeyDown, routine_id("lv_onKeyDown"))

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")

WinMain(MainWin, Normal)


C. K. Lester wrote:
> In a Winblows Explorer window, you can press 'F2' to "Rename" the 
> selected
> file. It actually lets you modify the name within the list itself. How 
> do I
> accomplish this functionality with Win32Lib?
> 
> I've attached a screen shot (only 16KB).
> 
> Thanks,
> ck
> 
>

new topic     » topic index » view message » categorize

2. RE: 'F2' to Edit Item in ListView

Funny enough, that's why I figured out how to edit a list view column.  
I wanted to be able to edit one or more than one column in a list view.  
Unfortunately, as I found out, you can only edit the first column in a 
MS list view.  

I suggest (strongly) that if you want to edit more than just the first 
column check out Phil Russel's EuGrid control.  I highly recommend it!

Jonas
C. K. Lester wrote:
> Jonas wrote:
> 
> > Attached is some code I posted a while back that let's you edit the
> > first column of a list view (note that you can only edit the first
> > column in a list view, as Derek pointed out).
> 
> How do I make it so I can edit the second column as well? Do I need to 
> use a
> different control for this functionality?
> 
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu