I need to "Float" a textbox over a listview subitem to make the
appearance of editing a subitem. I have the detection code for
which subitem was clicked and row, but everything I found was
using the x, y coordinates of the mouse click which does not
accurately position the textbox within the sub item.
How can I set a textbox coordinates to match the subitems
rectangular coordinates? Maybe something like getting the RECT
of the subitem somehow?
Thanks.
Last edited by RobDog888; Aug 19th, 2004 at 10:44 AM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
RobDog,
what I did is I created a flat textbox and just moved it to a given cell (curselrow and curselcolumn) and made the width/height of the textbox to the width of the columnheader. Although it's a cheap way, it works perfect. The only trick is, make sure the column is visible before displaying the textbox. I'll take a look at the code from the url you provided, maybe, if it's good enough, i'll replace my current functions with it.
I found a demo project at the site referenced by the thread. It
looks promissing, but when your editing (showing the textbox)
and the user scrolls the listview, the textbox does not move
accordingly. Getting closer though. Logic is similar to what I was
using to start and yours too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
OK i got this rect thing to work. Add a listview, commandbutton, label and a textbox (no need to rename them or modify them):
VB Code:
Option Explicit
Const LVM_GETITEMRECT = (&H1000 + 14)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Set iitem = ListView1.ListItems.Add(, , "test" & x)
iitem.SubItems(1) = "testsub" & x
Next x
End Sub
looks promissing, although my results returned pretty much the same values using columnwidth array. The only problem is the textbox refuses to stay the height i make it using row's height. I dont know why it always make itself 360 in height even if i make it 255 (default row height) or what not.
Last edited by Dmitri K; Aug 17th, 2004 at 05:48 PM.
You need to use the LVIR_LABEL constant to inform the
sendmessage function that it is in report mode and get the label
rect. Also, you need to populate the rect in the sendmessage api
with the top and left properties only. Top = subitem index and left
= LVIR_LABEL value.
So I almost have it resolved except for the height and the left
offset. It seems that it always puts the textbox a little to the right
of the beginning of the subitem and the height does not
completely fit. Perhaps because of the font size cant be chopped
off.
Ps. also use the setparent api to make the textbox a child of the
listview so when it scrolls the textbox follows.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Ok, well here's my code for this kind of stuff. By the way, the left and top are in offset beause of the border of the lsitview. For some reason with flat appearance it's still as with 3d appearance but the code below works for either.
see if it works better. If it doesn't than let me know, maybe I can use your method.
Oh by the way, this code does not take into consideration if column is invisible (partially). The only way I know how to fix that is make listview the width of the (example) currentcol.left + currentcol.width.
Just edited this post:
hmm, this LVM_SCROLL scrolls horizontally. I'll see if i can make this work.
Last edited by Dmitri K; Aug 17th, 2004 at 07:21 PM.
I like the demo, but not the hover effect. Kind of annoying.
I think I found a simpler method to handel the user scrolling the
listview when the textbox is being displayed. I disable them. This
will be enabled when the textbox is hidden by way of esc or
enter keys.
By the way, you need to subclass the listview because if the user
clicks somewhere outside of your app, the lost focus event will
not fire and you will not be able to determine when to hide the
textbox. You can trap for the WM_KILLFOCUS and WM_DESTROY
messages. When you come accross them you hide the textbox
setting the subitem's text back to original value.
VB Code:
Public Declare Function EnableScrollBar Lib "user32.dll" (ByVal hwnd As Long, ByVal wSBflags As Long, _
If you use the common controls v. 5.0 for your listview you can
use the SetParent api to link the textbox to the subitem. Then if
the user scrolls the textbox will follow the subitem perfectly. I
dont know why it doesn't work on 6.0 though? Otherwise you
can just use the MapWindowPoints API to set the textbox to the
subitem RECT.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I just went with the listview in common controls 6.0 and disabled
the scrollbars. In 5.0 the setparent api works for scrolling but if
you scroll beyond the viewable area then it gets messed up. So it
looks like I will have to settle for disabling the scrollbars.
Thanks to all.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I've been playing around with your editable listview.
I'm not able to convert it for working with an array of listviews.
Are you able to upgrade the code, so it will work with arrays?