datagridview列的drag&drop

delectation 2008-10-30 11:44:57
在实现datagridview列的drag&drop时,我先保存目标列的值和列的样式,再删除目标列。


//copy 源列的列头cell到新列
this.Columns[DragDropTargetIndex].HeaderCell = DragDropColumn.HeaderCell;
//让新插入的一列处于选择状态。
this.Columns[DragDropTargetIndex].Selected = true;
//update 当前cell在DataGridView中的位置
this.CurrentCell = this[DragDropTargetIndex, 0];
//再对目标列赋值
for (int i = 0; i < this.RowCount; i++)
{
if (DragDropColumnCellValue[i] != null)
{
this.Rows[i].Cells[DragDropTargetIndex].Value = DragDropColumnCellValue[i];
}
}

drag成功了,可是一排序。drag column的值被清空了。

这样实现datagridview列的拖动有什么问题,
应该怎么实现呢??
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpio 2008-10-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cpio 的回复:]
拖动不是自动实现的吗?
[/Quote]

自带的不是自动能拖。

用第三方控件的吧,已经实现了拖放。

或者看看这样行不行,如果可以了,说明通过引用传値的话,引用值只能属于一列,另一列可能就没有了。

this.Rows[i].Cells[DragDropTargetIndex].Value = DragDropColumnCellValue[i].ToString()

cpio 2008-10-30
  • 打赏
  • 举报
回复
拖动不是自动实现的吗?
crennah 2008-10-30
  • 打赏
  • 举报
回复
这种情况下是不是最好应该对DataSet而不是DataGridView进行操作呢
pvgyetg 2008-10-30
  • 打赏
  • 举报
回复
友情UP

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧