Results 1 to 3 of 3

Thread: [RESOLVED] How to get Top position of LV contained in TLP in SplitContainer

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    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
  •  



Click Here to Expand Forum to Full Width