如何使用调用功能读取listview并将其加载到listbox上 [英] How to read listview and load them on listbox using call function

查看:94
本文介绍了如何使用调用功能读取listview并将其加载到listbox上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我有关如何从列表视图中读取代码以及如何使用调用函数在列表框上生成代码的信息.
我知道可以从数据库中读取并将其生成到列表框,但是如何使用调用函数实现listview.这是一个列表框如何从数据库读取并在列表框上生成它们的示例.

列表框正在从数据库中读取,如何使其从活动列表视图中读取.


Can anyone tell me the codings as to how to read from listview and generate them on listbox using call function.
I know it''s possible to read from database and generate them onto listbox but how about listview using call function. here''s a sample of what how a listbox is able to read from a database and generate them on the listbox.

the listbox is reading from database, how does one make it to read from an active listview.


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

推荐答案

)",FormatCurrency(frmPurchaseItem.lblTotalAmount.Text))) ListBox1.Items.Add(字符串 .Format(fmtstr2," 现金" ,FormatCurrency(frmPurchaseItem.txtPaid.Text))) ListBox1.Items.Add(字符串 .Format(fmtstr2," 更改金额(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(" ) ListBox1.Items.Add(" 什么都没有 结束
)", 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


这篇关于如何使用调用功能读取listview并将其加载到listbox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆