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

关于C# listView控件里面的"行"拖动有关问题?初学者,高手见谅.

2012-02-01 
关于C# listView控件里面的行拖动问题???菜鸟,高手见谅...public void listView_ItemDrag(object sender

关于C# listView控件里面的"行"拖动问题???菜鸟,高手见谅...
public void listView_ItemDrag(object sender, ItemDragEventArgs e)
  {
  m_listView.DoDragDrop(e.Item, DragDropEffects.Move);
  }

  //在将对象拖入控件的边界时发生
  public void listView_DragEnter(object sender, DragEventArgs e)
  {
  e.Effect = e.AllowedEffect;
  }

  //在将对象拖入控件的边界上发生
  public void listView_DragOver(object sender, DragEventArgs e)
  {
  //将指定屏幕点的位置计算成工作区坐标
  Point targetPoint = m_listView.PointToClient(new Point(e.X, e.Y));

  //拖动时,寻找最近的预放位置
  int targetIndex = m_listView.InsertionMark.NearestIndex(targetPoint);

  if (targetIndex > -1)
  {
  Rectangle itemBounds = m_listView.GetItemRect(targetIndex);
  if (targetPoint.X > itemBounds.Left + (itemBounds.Width / 2))
  {
  m_listView.InsertionMark.AppearsAfterItem = true;
  }
  else
  {
  //"AppearsAfterIte" 获取或设置一个值,该值指示是否在项的右侧显示插入标记,该项带有 Index 属性指定的索引
  m_listView.InsertionMark.AppearsAfterItem = false;
  }
  }

  m_listView.InsertionMark.Index = targetIndex;
  }

  //在将对象拖出控件的边界时发生
  public void listView_DragLeave(object sender, EventArgs e)
  {
  m_listView.InsertionMark.Index = -1;
  }

  //在完成拖放操作时发生
  public void listView_DragDrop(object sender, DragEventArgs e)
  {
  DragDrop_Index = m_listView.InsertionMark.Index;

  if (DragDrop_Index == -1)
  {
  return;
  }

  if (m_listView.InsertionMark.AppearsAfterItem)
  {
  DragDrop_Index++;
  }

  ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));

  m_listView.Items.Insert(DragDrop_Index, (ListViewItem)draggedItem.Clone());

  m_listView.Items.Remove(draggedItem);

  //传递 "from" 和 "to" 的值
  m_pView.MoveTo(layerIndex, DragDrop_Index);
  }

问题是想在"listView_ItemDrag"一开始拖动的时候就拿到该拖动行的"索引值"???高手帮忙!!!

[解决办法]
你的意思是不是在listView_ItemDrag事件加一句:
m_listView.SelectedItems[0].Index.ToString();
我是菜鸟,说错了别怪啊
[解决办法]
拖拽ListView中的Item内容的源代码
remex 著于2007-8-4 10:14:33
本文实现的功能是在ListView或DataGrid中,拖动行,同时还可以移动行到别的控件中...

[解决办法]
m_listView.SelectedIndex;
用这个属性就可以了

热点排行