首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

ListBox中拖放遇到的奇特有关问题,谢谢啦,分立给?

2012-01-14 
ListBox中拖放遇到的奇特问题,多谢啦,分立给??????????就是想在ListBox中实现选项的拖放,MouseDown,DragDr

ListBox中拖放遇到的奇特问题,多谢啦,分立给??????????
就是想在ListBox中实现选项的拖放,MouseDown,DragDrop和DragOver的代码如下:
private   void   listBox1_MouseDown(object   sender,   System.Windows.Forms.MouseEventArgs   e)
{

index_src=((ListBox)sender).IndexFromPoint(e.X,e.Y);
if   (index_src!=ListBox.NoMatches)
{
((ListBox)sender).DoDragDrop((string)(listBox1.Items[index_src]),DragDropEffects.All);
}
}

private   void   listBox1_DragOver(object   sender,   System.Windows.Forms.DragEventArgs   e)
{
if   (e.Data.GetDataPresent(typeof(string))&&((ListBox)sender).Equals(listBox1))
e.Effect=DragDropEffects.Move;
else
e.Effect=DragDropEffects.None;
}

private   void   listBox1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)
{
ListBox   listbox=(ListBox)sender;
index_dst=listbox.IndexFromPoint(listbox.PointToClient(new   Point(e.X,e.Y)));
if   (index_dst!=ListBox.NoMatches)
{
string   temp=   listbox.Items[index_dst].ToString();
listbox.Items[index_dst]=listbox.Items[index_src];
listbox.Items[index_src]=temp;
listbox.SelectedIndex=index_dst;
}
}
编译可以通过,但拖放时效果很奇特,选中某项左键按下后拖放,鼠标下出现移动的标志,但是拖到ListBox中的任何区域都没反应,点下N次左键后鼠标恢复正常.之后每点一个选项,那个选项都会被删除,直到删完为止.大家有遇到过没,在线等,多谢.

[解决办法]
没有碰到过,帮顶
[解决办法]
我测试过,没什么问题 .NET 2.0

listBox1.AllowDrop属性记得要设置为true

热点排行