How to read listview and load them on listbox using call function

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Can anyone tell me the codings as to how to read from listview and generate them on listbox using call function.<br/>
I know its possible to read from database and generate them onto listbox but how about listview using call function. heres a sample of what how a listbox is able to read from a database and generate them on the listbox.<br/>
<br/>
the listbox is reading from database, how does one make it to read from an active listview.
<pre class="prettyprint lang-vb Private Sub frmReceipt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= luggageb.mdb"
Dim objConnection As New OleDbConnection(strConnection)

Dim fmtStr As String = "{0, -14} {1, -8} {2, -1} "
Dim fmtstr1 As String = "{0, -14} {1,-8} {2, -1} {3, -10}"
Dim fmtstr2 As String = "{0,-34}{1,-18}"
Dim fmtstr3 As String = "{0, -16} {1,-10} {2, -5} {3, -1:C}"
Try

objConnection.Open()
Catch OleDbExceptionErr As OleDbException
MessageBox.Show(OleDbExceptionErr.Message)
Catch InvalidOperationErr As InvalidOperationException
MessageBox.Show(InvalidOperationErr.Message)

End Try

Dim strSQL As String = "SELECT Transaction_ID, Purchase_ID, ItemNo, ItemPrice, ItemQuantity, TotalPrice FROM tblPurchase WHERE Transaction_ID = " & frmPurchaseItem.mskTransaction.Text & ""
Dim objCommand As New OleDbCommand(strSQL, objConnection)


Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim dgvTransaction As New DataTable("tblPurchase")
objDataAdapter.Fill(dgvTransaction)



objConnection.Close()
objConnection.Dispose()
objConnection = Nothing
objCommand.Dispose()
objCommand = Nothing
objDataAdapter.Dispose()
objDataAdapter = Nothing

ListBox1.Items.Add(" ########## ")
ListBox1.Items.Add(" #################### ")
ListBox1.Items.Add("=======================================================")

Call ListBox1.Items.Add(String.Format(fmtStr, "Date Purchase : " & frmPurchaseItem.dtpPurchaseDate.Text, " ", " ", " "))
Call ListBox1.Items.Add(String.Format(fmtStr, "Cashier Name : " & frmPurchaseItem.mskStaffID.Text, " ", " ", " "))
Call ListBox1.Items.Add(String.Format(fmtStr, "Receipt No: : " & frmPurchaseItem.mskTransaction.Text, " ", " ", " "))
Call ListBox1.Items.Add(String.Format(fmtStr, "Payment Method: : " & frmPurchaseItem.cbPaymentMenthod.Text, " ", " ", " "))

ListBox1.Items.Add(" ")
ListBox1.Items.Add("-------------------------------------------------------------------------- ")
Call ListBox1.Items.Add(String.Format(fmtstr1, "Purchase_ID", "Item No ", "Quantity ", "Price"))
ListBox1.Items.Add("-------------------------------------------------------------------------- ")

For Each Row As DataRow In dgvTransaction.Rows

FOR CALCULATION


Call ListBox1.Items.Add(String.Format(fmtstr3, Row.Item("Purchase_ID"), Row.Item("ItemNo"), Row.Item("ItemQuantity"), FormatCurrency(Row.Item("TotalPrice"))))
Call ListBox1.Items.Add(frmPurchaseItem.mskItemID.Text)
Call ListBox1.Items.Add(frmPurchaseItem.txtItemQuantity.Text)
Call ListBox1.Items.Add(frmPurchaseItem.txtItemPrice.Text)
ListBox1.Items.Add(" ")

Next


ListBox1.Items.Add(" ")
ListBox1.Items.Add(" ")

ListBox1.Items.Add(String.Format(fmtstr2, "Total Amount (B$)", FormatCurrency(frmPurchaseItem.lblTotalAmount.Text)))
ListBox1.Items.Add(String.Format(fmtstr2, "Cash", FormatCurrency(frmPurchaseItem.txtPaid.Text)))
ListBox1.Items.Add(String.Format(fmtstr2, "Change Amount (B$)", FormatCurrency(frmPurchaseItem.lblChange2.Text)))



ListBox1.Items.Add(" ")
ListBox1.Items.Add(" ")

ListBox1.Items.Add("=============================================================")
ListBox1.Items.Add(" Goods Are Not Returnable ")
ListBox1.Items.Add(" Thank You Please Come Again ")
ListBox1.Items.Add("=============================================================")



dgvTransaction.Dispose()
dgvTransaction = Nothing
End Sub
[/code]
<br/>


View the full article
 
Back
Top