关于WInform中listbox鼠标拖动上下排序item的问题解决
来源:互联网 发布:java进程占用cpu高 编辑:程序博客网 时间:2024/05/21 00:19
最近鼓弄这个地方好长时间 在网上搜罗 这块儿的东东好少哟
不过有代码的 我调试了 总没反应
后来终于解决 原因是我的listbox的datasource是绑定一个datatable的
so ... 从dt下手 代码如下
1、没datasource绑定的
private void lsb_Para_DragDrop(object sender, DragEventArgs e)
{
ListBox listbox = (ListBox)sender;
indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
if (indexoftarget != ListBox.NoMatches)
{
listbox.Items.RemoveAt(indexofsource);
listbox.Items.Insert(indexoftarget, obj);
listbox.SelectedIndex = indexoftarget;
}
}
private void lsb_Para_DragOver(object sender, DragEventArgs e)
{
//拖动源和放置的目的地一定是一个ListBox
if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lsb_Para))
{
e.Effect = DragDropEffects.Move;
}
else
e.Effect = DragDropEffects.None;
}
private void lsb_Para_MouseDown(object sender, MouseEventArgs e)
{
indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
if (indexofsource != ListBox.NoMatches)
{
((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.Move);
}
}
2、有绑定的
private void lsb_Visible_DragDrop(object sender, DragEventArgs e)
{
ListBox listbox = (ListBox)sender;
indexoftarget = listbox.IndexFromPoint(listbox.PointToClient(new Point(e.X, e.Y)));
if (indexoftarget != ListBox.NoMatches)
{
object obj = listbox.Items[indexofsource];
DataTable dt = (DataTable)listbox.DataSource;
DataRow dr = dt.NewRow();
dr["id"] = dt.Rows[indexofsource][0].ToString();
dr["hang_name"] = dt.Rows[indexofsource][1].ToString();
dt.Rows.RemoveAt(indexofsource);
dt.Rows.InsertAt(dr, indexoftarget);
listbox.SelectedIndex = indexoftarget;
for (int i = 0; i < dt.Rows.Count; i++)
{
string sql_updte = "update t_opr_hang set hang_paixu=" + (i + 1) + "where id=" + dt.Rows[i][0];
try
{
dbc.ExecuteSql(sql_updte);
Bind_Lsb_Para();
}
catch { }
}
}
}
private void lsb_Visible_DragOver(object sender, DragEventArgs e)
{
//拖动源和放置的目的地一定是一个ListBox
if (e.Data.GetDataPresent(typeof(System.String)) && ((ListBox)sender).Equals(lsb_Visible))
{
e.Effect = DragDropEffects.Move;
}
else
e.Effect = DragDropEffects.None;
}
private void lsb_Visible_MouseDown(object sender, MouseEventArgs e)
{
indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
if (indexofsource != ListBox.NoMatches)
{
((ListBox)sender).DoDragDrop(((ListBox)sender).Items[indexofsource].ToString(), DragDropEffects.Move);
}
}
区别在于从dt操作还是直接remove和insert
大家加油
- 关于WInform中listbox鼠标拖动上下排序item的问题解决
- 关于WInform中listbox鼠标拖动上下排序item的问题解决
- 关于WInform中listbox鼠标拖动上下排序item的问题解决
- 在winform的listbox中进行拖动排序
- .net C# listbox的上下移动,拖动排序,两个listbox相互拖动
- 利用javascript设定listBox中各Item的上下顺序
- winform的listbox拖动(拖拽)排序实例,源码在下方免积分下载
- 利用javascript设定listBox中各Item的上下顺序 [zhuan]
- 在C#中实现listbox的项上下移动(winform)
- WPF中ListBox相应鼠标滚动上下翻
- WinForm中ListBox的数据源
- Silverlight 4.0 可拖动排序的ListBox
- VB.Net程序设计:ListBox拖动排序两个ListBox的操作
- telerik中ListBox拖动中对象变化问题解决
- ListCtrl鼠标拖动Item
- ListBox中增加item的双击事件
- # winform listView鼠标拖拽到pictureBox问题的解决办法,鼠标拖动
- C# winform listBox中的项上下移动
- 笔记1
- (转)Struts 1和 Struts 2的区别和对比
- C#命名规范
- 关于排序之综述(转了大部分)
- 关于排序之二分查找特定元素
- 关于WInform中listbox鼠标拖动上下排序item的问题解决
- 就业关键_个人职业规划(1)--个人职业规划的意义
- 真的很有用
- 李开复给女儿的一封信
- 就业指导系列讲座 第三讲简历编写 幻灯片下载
- Ajax的外观设计:CSS样式表
- Android游戏开发使用View还是SurfaceView
- 蜗居的经典台词(幽默篇)
- Android Virtual Device仿真界面对应快捷