|
-
Feb 17th, 2015, 07:18 PM
#1
Thread Starter
PowerPoster
[RESOLVED] How to get Top position of LV contained in TLP in SplitContainer
Hello all,
For years I have been using the technique to simulate an "editable listview", where on MouseUp, depending on which subitem is clicked, I float a textbox or combobox on that "cell", and the user can then "edit" that cell. Apparently I have always done this where the ListView is placed directly on the form, and did not have a problem with the float positioning.
Now I had to modify such a form where the ListView is now contained (docked) within the second row of a TableLayoutPanel, which itself is docked in the second (bottom) panel of a SplitContainer.
So now of course when my ListView MouseUp routine refers to "ListView1.Top" and "ListView1.Left", those positional values are relative to the container, which in this case is in the second row of the TLP, which again is contained within the bottom panel of the SplitContainer. (So obviously my floating textbox or combobox pops up in the wrong place.)
What would be the proper syntax to add the correct displacement to "ListView1.Top" and "ListView1.Left" so that I get its "absolute" top and left positions relative to the form itself? I know I need to add "SplitContainer1.Panel2.Top", but it appears that adding the right values for the TLP is a little trickier.
Any and all help appreciated ...
Last edited by BruceG; Feb 17th, 2015 at 11:53 PM.
Reason: resolved
"It's cold gin time again ..."
Check out my website here.
-
Feb 17th, 2015, 07:42 PM
#2
Re: How to get Top position of ListView contained in TableLayoutPanel in SplitContain
Firstly, why not just use a DataGridView instead of a ListView? That way you do not have to simulate anything.
As for the question, you can use a control's PointToScreen and PointToClient methods to translate coordinates between frames of reference. For instance, this:
Code:
Dim tb As New TextBox
tb.Location = Me.PointToClient(ListView1.PointToScreen(Point.Empty))
Me.Controls.Add(tb)
is going to place the new TextBox at the same location as ListView1 no matter what the hierarchy of controls is.
-
Feb 17th, 2015, 11:45 PM
#3
Thread Starter
PowerPoster
Re: How to get Top position of ListView contained in TableLayoutPanel in SplitContain
Thanks, jmcilhinney, I was able to implement your suggestion.
Old code:
Code:
ClickedItem.Y += Me.lvwOrderItems.Top
ClickedItem.X += Me.lvwOrderItems.Left
New code:
Code:
Dim objLVLoc As Drawing.Point
objLVLoc = Me.PointToClient(lvwOrderItems.PointToScreen(Point.Empty))
ClickedItem.Y += objLVLoc.Y
ClickedItem.X += objLVLoc.X
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|