タイトル : Re: ListBox MultiExtended 選択行のIndex 投稿日 : 2012/04/09(Mon) 19:28 投稿者 : 魔界の仮面弁士
> .NETでは、任意のIndexを返すようで、具体的にはSelectedIndexies(0)の > Indexを返すようです。 SelectionMode プロパティが単一選択モードのときには LB_GETCURSEL をSendMessage して取得していますが、 複数選択時には、御推察通りの動きになっているようです。 > ListBoxで選択された最後の行を調べて、似たような機能を実現できる > ように自作コードを書いています。 ListBox を継承して、LB_GETCURSEL を SendMessage するプロパティを用意するか、 あるいは NativeWindow クラス経由で LB_GETCURSEL してやれば良さそうです。 なお LB_GETCURSELは、VB6 の ListBox.ListIndex プロパティと同様に、 フォーカスのあるIndex値を選択されているかどうかに関係なく返します。 Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Label1.Text = CStr(ListBox1.GetSelectedIndex()) _ & vbCrLf & CStr(ListBox1.SelectedIndex) End Sub End Class Module ListBoxExtensions <System.Runtime.CompilerServices.Extension()> _ Public Function GetSelectedIndex(lb As ListBox) As Integer Dim m As New Message() m.HWnd = lb.Handle m.Msg = &H188 'LB_GETCURSEL Dim n As New NativeWindow() n.AssignHandle(lb.Handle) n.DefWndProc(m) n.ReleaseHandle() Return m.Result End Function End Module |