Jump to content
David Schwartz

GridPanel question

Recommended Posts

I have a gridpanel with some buttons on it, and I want to be able to move them around using the mouse (drag-n-drop). I found this article:

 

https://stackoverflow.com/questions/5359948/drag-n-drop-controls-in-a-gridpanel

 

The problem is it simply swaps the source and destination buttons. What I want is to move the source button to the spot where the destination button is and then have all of the others move up or down as needed.

 

For example, if I have a list of 10 words, and I drag line 8 to line 3, I want it to push lines 3-7 down by one and leave this one at line 3. 

 

The gridpanel already has some flow logic built-in, but it's unclear whether you can use it to move things around. There's an Insert method, for example, but they say not to use it. Instead you merely change it's parent. 

 

The general behavior is to add something to the panel by assigning its parent and it's added at the end. But if you delete something, it closes the gap that's left.

 

Several of the methods and properties have no explanation, so it's not clear if this is a linear thing that can be accomplished by moving items around in the ControlCollection, or if you need to move them one-at-a-time from one (col,row) spot in the grid to the next. There aren't many examples I've found online for this control either.

 

Does anybody here have any experience with this?

Edited by David Schwartz

Share this post


Link to post
2 hours ago, David Schwartz said:

What I want is to move the source button to the spot where the destination button is and then have all of the others move up or down as needed.

Sounds like a TFlowPanel may be better suited for that. Just set the Control.Parent to the FlowPanel and then use FlowPanel.SetControlIndex to move it to the desired position.

 

 

Share this post


Link to post
9 hours ago, Uwe Raabe said:

Sounds like a TFlowPanel may be better suited for that. Just set the Control.Parent to the FlowPanel and then use FlowPanel.SetControlIndex to move it to the desired position.

 

 

Thanks, I'll check into that!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×