在vb.net中如何在textbox里显示listbox里的文件路径?

2024-11-15 20:45:31
推荐回答(2个)
回答(1):

Imports System.IO

Public Class Form4

Private Sub ButtonCreatPrg_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ButtonCreatPrg.Click
If Directory.Exists(TextBox_PrgPos.Text) Then
If TextBox_PrgName.Text = "" Then
'可以在此检查项目是否重复建立.
MessageBox.Show("请输入一个有效的名称.")
Else
TextBox_CreatDate.Text = Now.ToString
Dim NewItem As New PrgInfo(TextBox_PrgName.Text, TextBox_PrgPos.Text, Now)
Dim NewItemList As List(Of PrgInfo)
If ListBox_AllPrg.Tag Is Nothing Then
NewItemList = New List(Of PrgInfo)
Else
NewItemList = CType(ListBox_AllPrg.Tag, List(Of PrgInfo))
End If
NewItemList.Add(NewItem)
ListBox_AllPrg.Tag = NewItemList
End If
End If
End Sub

Private Sub ListBox_AllPrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox_AllPrg.SelectedIndexChanged
If ListBox_AllPrg.SelectedIndex < 0 Then
Return
End If
If ListBox_AllPrg.Tag Is Nothing Then
Return
End If
Dim ItemList As List(Of PrgInfo)
ItemList = CType(ListBox_AllPrg.Tag, List(Of PrgInfo))
TextBox_PrgName.Text = ItemList(ListBox_AllPrg.SelectedIndex).PrgName
TextBox_PrgPos.Text = ItemList(ListBox_AllPrg.SelectedIndex).PrgPath
TextBox_CreatDate.Text = ItemList(ListBox_AllPrg.SelectedIndex).CreatDate
End Sub
End Class

Public Class PrgInfo

Public Sub New(ByVal SetPrgName As String, ByVal SetPrgPath As String, ByVal SetPrgDate As DateTime)
MyBase.New()
PrgName = SetPrgName
PrgPath = SetPrgPath
CreatDate = SetPrgDate
End Sub

Private _PrgName As String
Public Property PrgName() As String
Get
Return _PrgName
End Get
Set(ByVal value As String)
_PrgName = value
End Set
End Property

Private _PrgPath As String
Public Property PrgPath() As String
Get
Return _PrgPath
End Get
Set(ByVal value As String)
_PrgPath = value
End Set
End Property

Private _CreatDate As DateTime
Public Property CreatDate() As DateTime
Get
Return _CreatDate
End Get
Set(ByVal value As DateTime)
_CreatDate = value
End Set
End Property

End Class

回答(2):

这个是可以做到的。前提条件是你目前的工程以及建置过