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
ListViewSubItem まで見つかったら後は ListViewSubItemCollection.IndexOf で。
ありがとうございました。
Debug.Print("Index:" & info.Item.SubItems.IndexOf(subItem))
で解決です。
ツイート | ![]() |