想设置某个item下subitem的值,但是得不到item的索引,就是不知道它的行数,列数可以通过columns的范围来判断,行数就没辙了

解决方案 »

  1.   

    listView1.SelectedItems[0].Index这样?
      

  2.   

    是这个吗? 
    listView1.Items.IndexOf(item);
      

  3.   

    使用ListView.GetItemAt 方法 把鼠标的坐标转换后传到这个方法做为参数获取鼠标坐标下的Item。public ListViewItem GetItemAt (
    int x,
    int y
    )
    private void ListView1_MouseDown(object sender, MouseEventArgs e)
    {    ListViewItem selection = ListView1.GetItemAt(e.X, e.Y);    // If the user selects an item in the ListView, display
        // the image in the PictureBox.
        if (selection != null)
        {
            
        }
    }
      

  4.   

    我描述得有点问题,能上个图就好了,假设下面是个listviewitem   sub   sub   sub
    a       1     1     1
    b       2     2     2
    c       3     3     3我点其中某个subitem,想得到它的位置,该怎么办呢?
    sublist的位置应该可以用listView1.Items[index].GetSubItemAt(e.X, e.Y)确定
    但是我得不到index的值
      

  5.   

    对,我现在就是这么做的,但是如果加了多个subitem,我点击subitem无法得到它所属item,就是这里不能解决了,有办法吗
      

  6.   

    可以使用IndexOf啊。参考:
    private void listView1_MouseDown(object sender, MouseEventArgs e)
    {
    // Get the item at the mouse pointer.
    ListViewHitTestInfo info = listView1.HitTest(e.X, e.Y); ListViewItem.ListViewSubItem subItem = null; // Get the subitem 120 pixels to the right.
    if (info != null && info.Item != null)
    {
    subItem = info.Item.GetSubItemAt(e.X, e.Y);
    int index = listView1.Items.IndexOf(info.Item);
    }
    }