34
A
回答
69
這是一個快速下載和骯髒的應用程序。基本上我用一個按鈕和一個ListBox創建了一個Form。點擊按鈕後,ListBox會填入未來20天的日期(必須使用某些東西進行測試)。然後,它允許拖放列表框內重新排序:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.listBox1.AllowDrop = true;
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 20; i++)
{
this.listBox1.Items.Add(DateTime.Now.AddDays(i));
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (this.listBox1.SelectedItem == null) return;
this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Move);
}
private void listBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
Point point = listBox1.PointToClient(new Point(e.X, e.Y));
int index = this.listBox1.IndexFromPoint(point);
if (index < 0) index = this.listBox1.Items.Count-1;
object data = e.Data.GetData(typeof(DateTime));
this.listBox1.Items.Remove(data);
this.listBox1.Items.Insert(index, data);
}
3
如果您從未實施過拖放操作,首次需要幾個小時才能完成正確的操作,並且必須通讀文檔。特別是即時反饋和恢復列表,如果用戶取消操作需要一些想法。將行爲封裝到可重用的用戶控件中也需要一些時間。
如果您從來沒有做過拖放操作,請查看MSDN上的drag and drop example。這將是一個很好的起點,它可能需要半天才能完成。
0
另一種方法是使用the list-view控件,它是Explorer用來顯示文件夾內容的控件。這是比較複雜的,但實現項目拖動你。
2
7晚年。但對於任何人來說,這裏是代碼。
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (this.listBox1.SelectedItem == null) return;
this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Move);
}
private void listBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
Point point = listBox1.PointToClient(new Point(e.X, e.Y));
int index = this.listBox1.IndexFromPoint(point);
if (index < 0) index = this.listBox1.Items.Count - 1;
object data = listBox1.SelectedItem;
this.listBox1.Items.Remove(data);
this.listBox1.Items.Insert(index, data);
}
private void itemcreator_Load(object sender, EventArgs e)
{
this.listBox1.AllowDrop = true;
}
相關問題
- 1. jquery表列拖放與重新排序
- 2. jQuery - 拖放列表重新排序
- 3. Android - 拖放列表重新排列
- 4. 拖放以重新排列HTML列表
- 5. 使用MVVM拖放重新排序ItemsControl
- 6. 表拖放重新排序和列排序
- 7. 拖放重新排序
- 8. jqGrid拖放列重新排序
- 9. 拖放以重新排列列表框內的項目wpf
- 10. 使用jQuery拖放表列的排序
- 11. 使用ajax拖放功能重新排序列字段? PHP/jQuery
- 12. 使用拖放對HTML表格行重新排序
- 13. 在KendoUI列表視圖中拖放重新排序
- 14. Ext JS的重新排序拖放列表
- 15. 重新排序表格列與反應通過拖放
- 16. JQuery UI在多個列表上拖放和重新排序
- 17. 拖放重新排序 - 一次重新排列2個並排元素
- 18. 重新排列物品拖放
- 19. Javascript - 拖放字母(重新排列)
- 20. 拖動和重新排序Windows Phone中的列表框項目
- 21. jquery拖放和重新排序
- 22. 重新排序StackPanel的兒童拖放
- 23. jQuery的拖放掇重新排序
- 24. 如何使用拖放Primefaces對數據表中的列進行重新排序
- 25. 與拖放和簡單的GridView拖放重新排序
- 26. 拖放排序NG-重複
- 27. 通過在Android中拖放來重新排列列表
- 28. 如何通過拖放在html中重新排列列表框項目
- 29. WPF C#:通過拖放來重新排列列表框中的項目
- 30. 使用拖放重新排列堆疊面板中的圖像
...,不支持簡單的事情,象綁定列表項:( – nathanchere 2013-09-12 22:13:37
...也不在列表或詳細視圖中顯示時不會拖的工作。 – nathanchere 2013-09-14 02:54:26