在vb.net中如何在textbox里显示listbox里的文件路径?
我做一个程序,想让其实现如下功能,点击新建按钮,在textbox总输入新建的工程名称,点击确定按钮,新建的工程名显示在listbox中,再点击listbox中的工程名,工...
我做一个程序,想让其实现如下功能,点击新建按钮,在textbox总输入新建的工程名称,点击确定按钮,新建的工程名显示在listbox中,再点击listbox中的工程名,工程的路径及工程建立的时间显示在下方的textbox1和textbox2中
展开
2个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询