实现的需求,我通过拖动选中的用户行放到左边的机构节点上,从而实现用户改变组织机构的关系

贴代码

 private DataGridViewSelectedRowCollection sourceRowCollection = null;
private int rowIndexFromMouseDown; /// <summary>
/// 用户拖动到机构里改变所属机构关系
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvUser_MouseDown(object sender, MouseEventArgs e)
{
rowIndexFromMouseDown = dgvUser.HitTest(e.X, e.Y).RowIndex;
if (rowIndexFromMouseDown != -)
{
if (this.dgvUser.SelectedRows.Count > )
{
sourceRowCollection = this.dgvUser.SelectedRows;
}
}
else
{
sourceRowCollection = null;
}
} private void dgvUser_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (sourceRowCollection != null)
{
DragDropEffects effect = this.dgvUser.DoDragDrop(sourceRowCollection, DragDropEffects.Move);
if (effect == DragDropEffects.Move)
{
//在sourceGrid中移除选中行
foreach (DataGridViewRow row in sourceRowCollection)
{
this.dgvUser.Rows.Remove(row);
}
sourceRowCollection = null;
}
}
}
} private void tvwOrganize_DragDrop(object sender, DragEventArgs e)
{
try
{
if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
{
DataGridViewSelectedRowCollection rowCollection = e.Data.GetData(typeof(DataGridViewSelectedRowCollection)) as DataGridViewSelectedRowCollection;
if (rowCollection == null)
{
return;
}
string userid = (rowCollection[].DataBoundItem as DataRowView).Row["UserID"].ToString();
string organizeid = (rowCollection[].DataBoundItem as DataRowView).Row["OrganizeID"].ToString();
Point p = this.tvwOrganize.PointToClient(new Point(e.X, e.Y));
TreeViewHitTestInfo hitTest = tvwOrganize.HitTest(p.X, p.Y);
Organize organize = hitTest.Node.Tag as Organize;
if (organizeid != organize.OrganizeID && userBiz.UpdateUserOrganize(userid, organize.OrganizeID))
{
e.Effect = DragDropEffects.Move;
}
else
{ e.Effect = DragDropEffects.None; }
}
}
catch (Exception ex)
{
e.Effect = DragDropEffects.None;
}
} private void tvwOrganize_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
{
e.Effect = DragDropEffects.None;
return;
}
else
{
e.Effect = DragDropEffects.Move; //这个值会返回给DoDragDrop方法
}
}

最新文章

  1. Python的平凡之路(19)
  2. 《Java JDK7 学习笔记》课后练习题2
  3. C语言中运算符的口决
  4. Odoo 配置快速创建编辑按钮
  5. MyEclipse的 at com.genuitec.eclipse.ast.deploy.core.Deployment.&lt;init&gt;错误解决办法
  6. xmlns与targetNamespace
  7. Light OJ 1060 - nth Permutation(组合数)
  8. 在Apache上部署Django
  9. 如何打包成jar包自己看呢?
  10. SQL Server---触发
  11. (简单) POJ 3368 Frequent values,RMQ。
  12. Vue 非父子组件通信方案
  13. react-native-echarts在打包时出现的坑
  14. Hibernate(3)配置文件hibernate.cfg.xml
  15. 百度地图API密钥
  16. 平衡二叉树-AVL树(LL、RR、LR、RL旋转)
  17. 让google.com不跳转到google.com.hk
  18. shiro中OAuth2 集成
  19. lintcode-389-判断数独是否合法
  20. 【BZOJ2616】SPOJ PERIODNI 笛卡尔树+树形DP

热门文章

  1. 树形DP+二分(Information Disturbing HDU3586)
  2. 弦图的判定MCS算法(zoj1015)
  3. how to use automapper in c#, from cf~
  4. ACM之Java速成(1)
  5. 利用Hudson持续集成来执行Android自动化测试(转)
  6. JSon_零基础_005_将po(bean)对象转换为JSon格式的对象字符串,返回给界面
  7. java 超经漂亮验证码
  8. loadrunner具体实例教你如何进行结果分析
  9. asp显示记录条数
  10. 我的Windows naked apps