vb.net 中 listview 中编辑 可以用 ComboBox 选择编辑数据

Public Class ModifyLineData

    Dim mousePos As Point
    Dim pubListviewitem As ListViewItem
    Dim imgList As ImageList
    Dim pubParent As FrmInvoiceList
    Public Sub InitDataLine(ByVal dr As IDataReader, ByVal argTaxTypeStr As String, ByVal tax_rate As String, ByRef argParentForm As FrmInvoiceList)
        pubParent = argParentForm

        Dim listviewitem As ListViewItem

        ListView1.Items.Clear()
        ListView1.View = View.Details

        While dr.Read()
            listviewitem = New ListViewItem

            listviewitem.Text = dr("list_goods_name").ToString() '""

            'listviewitem.SubItems.Add(dr("list_goods_name").ToString())
            listviewitem.SubItems.Add(dr("list_tax_item").ToString())
            listviewitem.SubItems.Add(dr("list_standard").ToString())
            listviewitem.SubItems.Add(dr("list_unit").ToString())
            listviewitem.SubItems.Add(dr("list_number").ToString())
            listviewitem.SubItems.Add(dr("list_price").ToString())
            listviewitem.SubItems.Add(dr("list_price_kind").ToString())
            'listviewitem.SubItems.Add(dr("list_goods_name").ToString())
            listviewitem.SubItems.Add(argTaxTypeStr)
            listviewitem.SubItems.Add(tax_rate)

            ListView1.Items.Add(listviewitem)



        End While

        dr.Close()

    End Sub
  



    Private Sub ModifyLineData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Common.DisableCloseButton(Me)

        mousePos = New Point(0, 0)

        imgList = New ImageList()
        imgList.ImageSize = New Size(1, 20)
        ListView1.SmallImageList = imgList
        ListView1.GridLines = True
        ListView1.Controls.Add(ComboBox1)

        'ListView1.View = View.Details
        'ListView1.Items.Clear()
        'inittest()



        Dim tmpDt As DataTable = New DataTable

        tmpDt = ExcelHelper.ImportExcel(Application.StartupPath + "\InvoiceType.xls")

        ComboBox1.Items.Clear()

        For i As Int32 = 0 To tmpDt.Rows.Count - 1

            ComboBox1.Items.Add(tmpDt.Rows(i)("税收编码") + "||" + tmpDt.Rows(i)("商品和服务名称"))

        Next


    End Sub

    Private Sub ListView1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove

        mousePos.X = e.X
        mousePos.Y = e.Y

    End Sub

    Private Sub ListView1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick

        pubListviewitem = ListView1.GetItemAt(mousePos.X, mousePos.Y)

        ComboBox1.Text = pubListviewitem.SubItems(1).Text

        ComboBox1.Width = ListView1.Columns(1).Width
        ComboBox1.Height = imgList.ImageSize.Height

        ComboBox1.Location = New Point(pubListviewitem.Position.X + ListView1.Columns(0).Width, pubListviewitem.Position.Y)
        ComboBox1.Visible = True


    End Sub

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

        changeName()

    End Sub


    Private Sub changeName()

        ComboBox1.Text = ComboBox1.Text.Split("||")(0)
        For Each item As ListViewItem In ListView1.SelectedItems
            item.SubItems(1).Text = ComboBox1.Text
            'pubListviewitem.Text = ComboBox1.Text
            'pubListviewitem.SubItems(1).Text = pubListviewitem.Text + pubListviewitem.SubItems(8).Text
            ComboBox1.Visible = False
        Next

    End Sub

    Private Sub ListView1_AfterLabelEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles ListView1.AfterLabelEdit
        'pubListviewitem.SubItems(1).Text = pubListviewitem.Text + pubListviewitem.SubItems(8).Text
    End Sub

    Private Sub ButtonConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonYes.Click

        Me.ButtonYes.DialogResult = DialogResult.No

        Dim listPriceKind As Integer

        '   Dim listNumber As Integer
        Dim listNumber As System.Decimal
        Dim listPrice As System.Decimal
        'Dim taxOffPrice As System.Decimal
        Dim taxOffAmount As System.Decimal
        Dim totalAmount As System.Decimal
        Dim tax_rate As Integer

        '税收分类编码需要的变量
        'Dim contractAttr As String = ""
        Dim taxTypeStr As String
        Dim taxResStr As String = ""


        For Each item As ListViewItem In ListView1.Items



            Me.ButtonYes.DialogResult = DialogResult.Yes

            Call pubParent.mObjTaxCardX.InvListInit()

            taxTypeStr = item.SubItems(7).Text

            pubParent.mObjTaxCardX.ListGoodsName = item.SubItems(0).Text

            pubParent.mObjTaxCardX.ListTaxItem = item.SubItems(1).Text
            pubParent.mObjTaxCardX.ListStandard = item.SubItems(2).Text
            pubParent.mObjTaxCardX.ListUnit = item.SubItems(3).Text

            listNumber = System.Decimal.Parse(item.SubItems(4).Text)
            'listNumber = CInt(dr("list_number"))
            listPrice = System.Decimal.Parse(item.SubItems(5).Text)
            totalAmount = Decimal.Round(Decimal.Multiply(listPrice, listNumber), 2)

            pubParent.mObjTaxCardX.ListNumber = listNumber

            listPriceKind = CInt(item.SubItems(6).Text)
            If listPriceKind = 1 Then
                'taxOffPrice = Decimal.Divide(Decimal.Truncate(Decimal.Divide(listPrice, 0.0117)), 100)
                'taxOffPrice = Decimal.Divide(listPrice, 1.17)
                tax_rate = CInt(item.SubItems(8).Text)
                Dim tax_rate_pre As Decimal = 1 + tax_rate * 0.01
                taxOffAmount = Decimal.Round(Decimal.Divide(totalAmount, tax_rate_pre), 2)
                listPriceKind = 0
            Else
                listPriceKind = 0
            End If

            'mObjTaxCardX.ListPrice = Decimal.ToDouble(taxOffPrice)
            'mObjTaxCardX.ListAmount = Decimal.ToDouble(Decimal.Multiply(taxOffPrice, listNumber))
            'mObjTaxCardX.ListTaxAmount = Decimal.ToDouble(Decimal.Multiply(Decimal.Subtract(listPrice, taxOffPrice), listNumber))
            pubParent.mObjTaxCardX.ListAmount = taxOffAmount
            pubParent.mObjTaxCardX.ListTaxAmount = Decimal.Subtract(totalAmount, taxOffAmount)

            'MessageBox.Show( String.Format("listPrice:{0},listNumber:{1},totalAmount:{2},taxOffAmount:{3}, taxOffAmount:{4}", listPrice, listNumber, totalAmount, taxOffAmount, Decimal.Subtract(totalAmount, taxOffAmount)))

            '将税收分类编码通过BatchUpload传递过去。taxResStr是接收的返回结果,有问题,调试可用来看
            taxResStr = pubParent.mObjTaxCardX.BatchUpload(taxTypeStr)

            Call pubParent.mObjTaxCardX.AddInvList()


        Next



        Close()


    End Sub

    Private Sub ButtonClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNo.Click

        Me.ButtonYes.DialogResult = DialogResult.No
        Close()

    End Sub


    Private Sub ComboBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Leave
        changeName()
    End Sub

    Private Sub ModifyLineData_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Return
    End Sub


    Private Sub inittest()
        Dim listviewitem As ListViewItem

        listviewitem = New ListViewItem
        listviewitem.Text = "数字化校园电子设备"
        'listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("套")
        listviewitem.SubItems.Add("1")
        listviewitem.SubItems.Add("1800000")
        listviewitem.SubItems.Add("1")
        listviewitem.SubItems.Add("txt")
        'listviewitem.SubItems.Add("数字化校园电子设备")
        ListView1.Items.Add(listviewitem)

        listviewitem = New ListViewItem
        listviewitem.Text = "数字化校园电子设备"
        'listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("")
        listviewitem.SubItems.Add("套")
        listviewitem.SubItems.Add("1")
        listviewitem.SubItems.Add("1800000")
        listviewitem.SubItems.Add("1")
        listviewitem.SubItems.Add("txt")
        'listviewitem.SubItems.Add("数字化校园电子设备")


        ListView1.Items.Add(listviewitem)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Panel1.Controls.Add(ComboBox1)
        Try
            If ListView1.SelectedItems.Count > 0 Then

                ComboBox1.Width = ListView1.Columns(1).Width
                ComboBox1.Height = imgList.ImageSize.Height



                ComboBox1.Location = New Point(ListView1.SelectedItems(0).Position.X +
                                               ListView1.Columns(0).Width, ListView1.SelectedItems(0).Position.Y)
                ComboBox1.Visible = True

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try


    End Sub

    Private Sub ListView1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Validated

       
        Try
            For Each item As ListViewItem In ListView1.SelectedItems
                If Not item Is Nothing Then
                    item.BackColor = SystemColors.Highlight
                    item.ForeColor = Color.White
                    'ListView1.SelectedIndices.Add(item.Index)
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
      
      
    End Sub

    Private Sub ListView1_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
        Try
            For Each item As ListViewItem In ListView1.Items
                item.ForeColor = Color.Black
                item.BackColor = SystemColors.Window
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
     

        'e.Item.ForeColor = Color.Black
        'e.Item.BackColor = SystemColors.Window

        'If Not ListView1.FocusedItem Is Nothing Then
        '    ListView1.FocusedItem.Selected = True
        'End If


    End Sub

   
End Class

 

转载于:https://www.cnblogs.com/realso/p/8275907.html

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值