ListViewのMouseDown時のColumnIndex

解決


Taka  2008-10-24 17:45:47  No: 140723

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 18:33:18  No: 140724

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


Taka  2008-10-24 20:19:08  No: 140725

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

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

で解決です。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加