User-ordered list
Hi,
I have a list that I want the user to order via the GUI. What I had in mind is a control that resembles a List box populated with items, so the the user can click and drag them into order. What control should I use for this? It is a common type of control but I can't seem to find a pre-defined control doing exactly this.
Thanks..
Ruan RothmannPosted Jun 25, 2007, 3:58 AM
Mike GoldPosted Jun 21, 2007, 4:14 PM
Best,
-Mike
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;namespace
DraggableListBox{
public partial class DraggableListBoxComponent : ListBox{
public DraggableListBoxComponent(){
InitializeComponent();}
protected override void OnPaint(PaintEventArgs pe){
// TODO: Add custom paint code here // Calling the base class OnPaint base.OnPaint(pe);}
private string _dragData = ""; private int _selectedDragItemIndex = -1; private void DraggableListBox_DragEnter(object sender, DragEventArgs e){
if (e.Data.GetDataPresent(DataFormats.Text, true)){
e.Effect = DragDropEffects.All;}
}
private void DraggableListBox_DragDrop(object sender, DragEventArgs e){
Point p = this.PointToClient(new Point(e.X, e.Y)); int index = this.IndexFromPoint(p); if (index >= 0){
Items.RemoveAt(_selectedDragItemIndex);
Items.Insert(index, _dragData);
}
}
private void DraggableListBoxComponent_SelectedIndexChanged(object sender, EventArgs e){
}
private void DraggableListBoxComponent_MouseDown(object sender, MouseEventArgs e){
_selectedDragItemIndex = this.IndexFromPoint(e.X, e.Y); if (_selectedDragItemIndex >= 0) _dragData = (string)Items[_selectedDragItemIndex]; this.DoDragDrop(Items[this.SelectedIndex].ToString(), DragDropEffects.Move);}
}
}
Posted Jun 21, 2007, 10:33 AM
I could be wrong and someone please correct me if I am, but I dont think it can be done without some serious coding.