using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid;
// 声明:
private GridHitInfo downHitInfo;
设置多行选中
GridView1.OptionsSelection.MultiSelect = true;
//事件处理:
//要拖动的数据
private void GridControl1_MouseDown(object sender, MouseEventArgs e)
{
downHitInfo = GridView1.CalcHitInfo(new Point(e.X, e.Y));
}
private void GridControl1_MouseMove(object sender, MouseEventArgs e)
{
if (downHitInfo == null) return;
if (e.Button != MouseButtons.Left) return;
Rectangle dragRect = new Rectangle(new Point(
downHitInfo.HitPoint.X - SystemInformation.DragSize.Width / 2,
downHitInfo.HitPoint.Y - SystemInformation.DragSize.Height / 2), SystemInformation.DragSize);
if (!dragRect.Contains(new Point(e.X, e.Y)))
{
DataRow data = GridView1.GetDataRow(downHitInfo.RowHandle);
int[] rows = GridView1.GetSelectedRows();
List<DataRow> row = new List<DataRow>();
for (int i = 0; i < rows.Length; i++)
row.Add(GridView1.GetDataRow((int)rows[i]));
GridControl1.DoDragDrop(row, DragDropEffects.Copy);
}
}
//要存放的GridControl
// 设置为可接受拖拽数据
GridControl2.AllowDrop = true;
private void GridControl2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void GridControl2_DragDrop(object sender, DragEventArgs e)
{
GridControl grid = sender as GridControl;
DataTable table = grid.DataSource as DataTable;
List<DataRow> row = e.Data.GetData(typeof(List<DataRow>)) as List<DataRow>;
if (row != null && table != null)
{
if (row.Count > 0)
{
for (int i = 0; i < row.Count; i++)
{
table.ImportRow(row[i]);
row[i].Delete(); // 把原有的数据行删除。
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Fing_king/archive/2010/08/01/5781591.aspx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)