The ListView control available from the Windows Common Controls does provide the ability to edit the labels of items. But, when set to Report mode, it only allows editing of the text in the first column. The SubItems in the other columns cannot be directly edited.
This module allows editing of the items in all columns. It uses a textbox to let the user edit listitems.
Unlike the previous version, the code is now placed inside a class. That makes it easier to use and doesn't clutter up existing code. Also multiple instances can run at once, so LabelEditing can be applied to several ListViews at the same time.
The code now works with ListViews with horizontal scrollbars.
You no longer have to place a textbox on your form for the editing; the class takes care of that by itself.
This code works with the Windows Common Controls 6 ListView (not with the Common Controls 5 component). With a bit of tweaking it can also be applied to the vbAccelerator ListView (in that case the subclassing code can be removed).
The ScaleMode of the form has to be 1-Twip for this code to work.
This is what I've been trying to do...
The code above posted by vader works nicely when theres 4 or more columns.
I was trying to figure out why when theres only 2 columns its only editing column 1. Even if I use the demo, set the LV for only 2 columns and click column2 samething.
I'm stumped... I tried changing somethings around, can't figure it out.
Anyone got any idea's ?
I've tried editing with two columns and it works fine for me... With only one column it gives an error, though.
This code could surely use an update. A bit more reliability wouldn't hurt, and the horizontal scrollbar problem pointed out by Danial should be fixed too.
Anyway, I attached an example with two columns, which works fine for me. Does that work?
I've completely revised the code today; the scrollbar bug has been fixed and the code is now much easier to implement. Check out the first post in the thread.
I started to think I had messed it up when I seen your reply post, cause you said it worked fine for you.. I've posted a picture just so you don't think I'm crazy.
Basically all I did to your demo just to check, was delete 2 columns..
But this pic is from the demo you said works for you. Samething.(Looks like your editing in col 2 but edits col 1)
But the revised code(class) seems to correct it. Being as you've made it into a class its much better and it works very nicely.. Thanks for your help and sharing...
Oh also why the subclassing ?
When I commented out the Call SubClassWnd(ltv.hwnd) to step through, it seemed to funtion the same.
To control painting?
Hi again,
Another question.. How would I go about capturing the tab key when in edit .
Like say you were editing in column 1 and you hit [tab].
I've tried different events of the txtEdit and the Listview.
KeyUp - Doesn't catch tab.
KeyDown - In a normal txtbox if I set tabstop=False this catches [tab] can't get it to work in the class.
KeyPress - Doesn't catch tab.
LostFocus - Reacts to tab but can't get keycode.
I'm tring to add like a tab order to the columns.
If your editing in col 1 hit tab and begin editing in col 2.
Thanks for any help\input
$hep
[RESOLVED]-The only way I could resolve this was to set every control's tabstop=false. But it works, its just dirty.
I've got this problem, (attached is the screenshot), why is it not fitted exactly? Here is the minor modifications I did so the editing will be triggered after double-click...
VB Code:
Dim xPos As Single, yPos As Single
Private Sub ltvListView_DblClick()
EditText xPos, yPos
End Sub
Private Sub ltvListView_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
xPos = x
yPos = y
End Sub
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
I've got this problem, (attached is the screenshot), why is it not fitted exactly? Here is the minor modifications I did so the editing will be triggered after double-click...
VB Code:
Dim xPos As Single, yPos As Single
Private Sub ltvListView_DblClick()
EditText xPos, yPos
End Sub
Private Sub ltvListView_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
xPos = x
yPos = y
End Sub
You need to make the style of the listview the same as the original, Appearence and BorderStyle set to 0. Or calculate those and reposition the textbox by adding those to your calculations.
Has someone helped you? Then you can Rate their helpful post.