VB.Net Datagridview添加数量现有值

时间:2016-06-28 11:03:40

标签: vb.net

我已将未绑定的Datagridview编入索引。我正在尝试添加Quantity +,代表Existing quantity plus

eg.:- Itemcode 001  Luxsoap  Quantity 10 .

同样,我想添加相同的产品数量10.如果它们已经添加,那么单元格总数将变为20。

如何实现此功能?我正在使用VB.NET未绑定的Datagridview。

这是我的代码: -  Dim rnum As Integer = DGVSale.Rows.Add()

    DGVSale.Rows.Item(rnum).Cells("ItemCode").Value = TxtSaleBarcode.Text
    DGVSale.Rows.Item(rnum).Cells("PrName").Value = TxTSaleItemName.Text
    DGVSale.Rows.Item(rnum).Cells("Price").Value = TxTSalePrice.Text
    DGVSale.Rows.Item(rnum).Cells("GrQty").Value = TxTSaleQty.Text
    DGVSale.Rows.Item(rnum).Cells("Amnt").Value = TxTSaleAmount.Text
    DGVSale.Rows.Item(rnum).Cells("InvNum").Value = TxTInvNo.Text
    DGVSale.Rows.Item(rnum).Cells("GstAmnt").Value = GSTcollect.Text

    'DGVSale.Rows.Item(rnum).Cells("QtyInHand").Value = LblDisplayQtyinHand.Text

    Dim Found As Boolean = False
    If DGVSale.Rows.Count > 0 Then
        'Check if the product Id exists with the same Quantity
        For Each row As DataGridViewRow In DGVSale.Rows
            If Convert.ToString(row.Cells(0).Value) = TxtSaleBarcode.Text AndAlso Convert.ToString(row.Cells(3).Value) = TxTSaleQty.Text Then
                'Update the Quantity of the found row
                row.Cells(0).Value = Convert.ToString(TxTSaleQty.Text + Convert.ToInt16(row.Cells(3).Value))
                Found = True

            End If
        Next

0 个答案:

没有答案