PDA

View Full Version : مبتدی: بدست آوردن آیتمی که ماوس بر روی آن اشاره دارد در listview



milad.biroonvand
چهارشنبه 05 اسفند 1388, 15:08 عصر
سلام دوستان ، من می خوام آیتمی رو که ماوس بالای اون هست رو بدست بیاورم ، با داشتن یک point از موقعیتی که ماوس بر روی اون هست (در list view ) برای اینکار از چه کدی استفاده میشه .

Hossis
چهارشنبه 05 اسفند 1388, 22:29 عصر
ديدم کسي جواب نداده خودم هم تابحال چنين کدي نياز ندشتم که بسازم، يک مثال از VB6 با API براتون مي ذارم اميدوارم که با تبديل اون به دات نت ، مشکل حل بشه


'Add ListBox to your form (named List1), and add some items to the ListBox's list.
'When you will move your mouse over one of the listbox's items,
'A ToolTipText will pop-up with the name of the item.
'Insert the following code to your module:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lXPoint As Long
Dim lYPoint As Long
Dim lIndex As Long
If Button = 0 Then
lXPoint = CLng(X / Screen.TwipsPerPixelX)
lYPoint = CLng(Y / Screen.TwipsPerPixelY)
With List1
lIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, ByVal _
((lYPoint * 65536) + lXPoint))
If (lIndex >= 0) And (lIndex <= .ListCount) Then
' .List(lIndex) contains the name of the item under the mouse cursor.
' if you want to display the item in textbox, simply write:
' Text1.Text =.List(lIndex)
.ToolTipText = .List(lIndex)
Else
.ToolTipText = ""
End If
End With
End If
End Sub

Hossis
چهارشنبه 05 اسفند 1388, 23:05 عصر
نيازي به کد بالا نيست ، همين يک خط مشکل رو حل مي کنه


Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
Dim s As ListViewItem
s = ListView1.GetItemAt(e.X, e.Y)
If s Is Nothing = False Then Me.Text = s.Text
End Sub