ListViewのMouseDown時のColumnIndex

解決


Taka  2008-10-24 08:45:47  No: 140723  IP: 192.*.*.*

MSDNライブラリで下記のようにListViewのMouseDownにより、該当
するItemおよびその場所にあるSubItemを得ることができることが
わかりました。

ListView1.View = View.Details のとき、対応するColumnHedder
あるいはそのIndexを得るにはどのような方法がありますでしょうか?

該当するSubItemがNothingの場合も可能な方法を考えています。

#各ColumnHedderのX座標でもわかれば計算できそうな気もしますが
#横スクロールの具合により判断が大変な予感がします。

Private Sub listView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    ' Get the item at the mouse pointer.
    Dim info As ListViewHitTestInfo = listView1.HitTest(e.X, e.Y)
    Dim subItem As ListViewItem.ListViewSubItem = Nothing
    ' Get the subitem 120 pixels to the right.
    If (info IsNot Nothing) Then
        If (info.Item IsNot Nothing) Then
            subItem = info.Item.GetSubItemAt(e.X + 120, e.Y)
        End If
    End If ' Show the text of the subitem, if found.
    If (subItem IsNot Nothing) Then
        MessageBox.Show(subItem.Text)
    End If
End Sub

編集 削除
Hongliang  2008-10-24 09:33:18  No: 140724  IP: 192.*.*.*

ListViewSubItem まで見つかったら後は ListViewSubItemCollection.IndexOf で。

編集 削除
Taka  2008-10-24 11:19:08  No: 140725  IP: 192.*.*.*

ありがとうございました。

Debug.Print("Index:" & info.Item.SubItems.IndexOf(subItem))

で解決です。

編集 削除