我为学校制作一个程序(在VB.NET中),我有一个listview。当用户输入客户名称并按“OK”时,它将在列表视图中输出为“o”
该程序的代码是:
Public Class Form1
Dim w As IO.StreamWriter
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstOutput.Items.Clear()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
End
End Sub
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim sfile As New SaveFileDialog
With sfile
.Title = "Choose your path to save the information"
.InitialDirectory = "C:\"
.Filter = ("ONLY Text Files (*.txt) | *.txt")
End With
If sfile.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim Write As New IO.StreamWriter(sfile.FileName)
Dim k As ListView.ColumnHeaderCollection = lstOutput.Columns
For Each x As ListViewItem In lstOutput.Items
Dim StrLn As String = ""
For i = 0 To x.SubItems.Count - 1
StrLn += k(i).Text + " :" + x.SubItems(i).Text + Space(3)
Next
Write.WriteLine(StrLn)
Next
Write.Close() 'Or Write.Flush()
End If
End Sub
Private Sub txtDiscPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnAdd_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim secondform As New Form2
secondform.ShowDialog()
Dim item As ListViewItem
item = lstOutput.Items.Add(secondform.CustomerName)
item.SubItems.Add(secondform.Item)
item.SubItems.Add(secondform.ItemPrice)
item.SubItems.Add(secondform.Quantity)
item.SubItems.Add(secondform.TotalPrice)
item.SubItems.Add(secondform.DiscPerc)
item.SubItems.Add(secondform.DiscPrice)
item.SubItems.Add(secondform.PaymentMethod)
End Sub
End Class
并且对于第二种形式,用户输入代码为的信息:
Public Class Form2
Public CustomerName As String
Public Item As String
Public ItemPrice As Double
Public Quantity As Integer
Public TotalPrice As Integer
Public DiscPerc As Double
Public DiscPrice As Double
Public PaymentMethod As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CustomerName = Val(txtCustName.Text)
Item = Val(txtItemName.Text)
ItemPrice = Val(txtItemPrice.Text)
Quantity = Val(txtQuantity.Text)
TotalPrice = Val(txtTtlPrice.Text)
DiscPerc = Val(txtDiscPerc.Text)
DiscPrice = Val(txtDiscPrice.Text)
PaymentMethod = Val(txtPaymentMethod.Text)
Me.Close()
End Sub
End Class
我多年来一直坚持这一点,感谢任何帮助!