On Sep 25, 7:29 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
Update :) Ok, finally i've solved the problem when pressed the cancel
button with help of Mr. Young at least.
But a problem arised again:
If i display files' names only by coding
"ListBox1.Items .Add(System.IO. Path.GetFileNam e(openfileplayl ist.FileName))" ,
i cannot set a linkage between selected item and play button for a
double-click launch for selected item. Why?
Here's my solution. Basically, we are going to use a custom object to
pass information to the ListBox when we add the item. Then all is
needed is to unbox the object and retrieve our properties. To use this
sample create a new Window's Forms Application and add a ListBox to
Form1. Then add the following to the code-behind:
///////////////////////
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'// Simulate items being added
Me.ListBox1.Ite ms.Add(New FileInformation ("FileName", "C:
\FilePath\FileN ame.MP3"))
Me.ListBox1.Ite ms.Add(New FileInformation ("FileName2" , "C:
\FilePath2\File Name2.MP3"))
End Sub
Private Sub ListBox1_Select edIndexChanged( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ListBox1.Select edIndexChanged
Try
Dim item As FileInformation =
DirectCast(Me.L istBox1.Selecte dItem, FileInformation )
MsgBox(String.F ormat("The path for item '{0}' is '{1}'",
item.FileName, item.FilePath), MsgBoxStyle.OkO nly, "File Information")
Catch ex As InvalidCastExce ption
MsgBox("The selected file was not found.")
'// Remove the item to prevent further troubles
Me.ListBox1.Ite ms.Remove(Me.Li stBox1.Selected Item)
End Try
End Sub
End Class
Public Class FileInformation
Public Sub New()
End Sub
Public Sub New(ByVal fileName As String, ByVal filePath As String)
Me.FileName = fileName
Me.FilePath = filePath
End Sub
Public Property FileName() As String
Get
Return _FileName
End Get
Set(ByVal value As String)
_FileName = value
End Set
End Property
Private _FileName As String = String.Empty
Public Property FilePath() As String
Get
Return _FilePath
End Get
Set(ByVal value As String)
_FilePath = value
End Set
End Property
Private _FilePath As String = String.Empty
Public Overrides Function ToString() As String
Return FileName
End Function
End Class
///////////////////////
Thanks,
Seth Rowe