Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TableLayoutPanel and Getting a Cell by Mouse position

TableLayoutPanel and Getting a Cell by Mouse position

Scheduled Pinned Locked Moved C#
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arefkarimi
    wrote on last edited by
    #1

    Hi All, I have a TableLayoutPanel on a form and I want to let the user drag and drop objects on to it. I need to find out on which cell the dragged object has been dropped. is there any way to do it? Thanks a lot

    Aref

    D 1 Reply Last reply
    0
    • A arefkarimi

      Hi All, I have a TableLayoutPanel on a form and I want to let the user drag and drop objects on to it. I need to find out on which cell the dragged object has been dropped. is there any way to do it? Thanks a lot

      Aref

      D Offline
      D Offline
      DannyAdler
      wrote on last edited by
      #2

      Hi there, What I would do is to create inside each cell a full-docked control, like an empty label, then on the TableLayoutPanel DragDrop event I'd get the cell by the position of the control: private void tableLayoutPanel1_DragDrop(object sender, DragEventArgs e) { Point p = tableLayoutPanel1.PointToClient(new Point(e.X, e.Y)); Control c = tableLayoutPanel1.GetChildAtPoint(p); TableLayoutPanelCellPosition cellPos = tableLayoutPanel1.GetCellPosition(c); } Try it, it's working. The cell that gets the drop is reprisented by cellPos.Row and cellPos.Column Hope that help. Danny

      U 1 Reply Last reply
      0
      • D DannyAdler

        Hi there, What I would do is to create inside each cell a full-docked control, like an empty label, then on the TableLayoutPanel DragDrop event I'd get the cell by the position of the control: private void tableLayoutPanel1_DragDrop(object sender, DragEventArgs e) { Point p = tableLayoutPanel1.PointToClient(new Point(e.X, e.Y)); Control c = tableLayoutPanel1.GetChildAtPoint(p); TableLayoutPanelCellPosition cellPos = tableLayoutPanel1.GetCellPosition(c); } Try it, it's working. The cell that gets the drop is reprisented by cellPos.Row and cellPos.Column Hope that help. Danny

        U Offline
        U Offline
        User 1855448
        wrote on last edited by
        #3

        Hello danny, What is the relevance of creating a full docked control as you have explained. It will be great if you could spare some time to explain. Thanks, CPM

        L 1 Reply Last reply
        0
        • U User 1855448

          Hello danny, What is the relevance of creating a full docked control as you have explained. It will be great if you could spare some time to explain. Thanks, CPM

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          ... because this code works only if there is some control at clicked position.

          tableLayoutPanel1.GetChildAtPoint(p)

          ... would return null without the full docked control at the background.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups