2

so i have a flow panel and a button that adds listviews to it at run time. i have my doubleclick events set up - is it possible to set up some kind of click (or click and drag) event to rearrange the controls in the flow panel?

i know we can change the sort strategy (top down, left right) and wrap, but i was hoping for organization a user could simply drag the control from one spot and relocated somewhere else.

private void addNewWOButton_Click(object sender, EventArgs e)
        {
            ListView newListView = new ListView();
            newListView.AllowDrop = true;
            newListView.DragDrop += listView_DragDrop;
            newListView.DragEnter += listView_DragEnter;
            newListView.DoubleClick += listView_DoubleClick;

            flowPanel.Controls.Add(newListView);
}
ikathegreat
  • 2,311
  • 9
  • 49
  • 80
  • 1
    Is what you're calling a "flowpanel" actually a `FlowLayoutPanel` control? – Cody Gray - on strike Jan 27 '12 at 02:53
  • 1
    possible duplicate of [Reordering of controls within a flow layout panel](http://stackoverflow.com/questions/425867/reordering-of-controls-within-a-flow-layout-panel)? Also see: http://www.codeproject.com/Articles/48411/Using-the-FlowLayoutPanel-and-Reordering-with-Drag – Cody Gray - on strike Jan 27 '12 at 02:55

1 Answers1

3

This will move a control to the top of the panel and move the remaining controls down.

            FlowLayoutPanel1.Controls.SetChildIndex(myControl, 0);

For drag and drop re-ordering, you'll have to hook up drag and drop events for each control. On the drop event get the control being dragged and the index position of the target control. Then change the index with SetChildIndex. If your still working on this problem, I can dig up some code to show you.

TK-421
  • 387
  • 2
  • 11