Check the value in datagridview column and if value is equal then add to textbox.
Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged
dt1.Clear()
txtTaxVal3.Text = ""
txtTaxVal12.Text = ""
txtTaxVal18.Text = ""
For Each item As Object In CheckedListBox1.CheckedItems
Dim cmd As New SQLiteCommand("Select itemcode,itemname,rate,qty,subtot,uom,youch,youchdt,pono,podt,hsn,batchno,itemtype,jwino,jwidt,pid,ichallid,challdt,compname,srno,GSTRate from ChallItem where ichallid = @ichallno", con1)
cmd.Parameters.AddWithValue("ichallno", item("ichallid"))
Dim da As New SQLiteDataAdapter(cmd)
da.Fill(dt1)
dgvBillItems.DataSource = dt1
Next
Call lsubtot()
Call TaxValue()
End Sub
Public Function TaxValue() As Decimal
' Dim value As String = dgvBillItems.Rows(0).Cells(20).Value.ToString()
For i As Integer = 0 To dgvBillItems.Rows.Count() - 1
If dgvBillItems.Rows(i).Cells(20).Value?.ToString = "3" Then
a = 0
b = 0
Try
b = dgvBillItems.Rows.Count
For a = 0 To dgvBillItems.Rows.Count - 1
tot1 += Convert.ToDouble(dgvBillItems.Rows(a).Cells(4).Value)
Next a
Catch ex As Exception
MsgBox(ex.Message)
End Try
txtTaxVal3.Text = tot1
End If
If dgvBillItems.Rows(i).Cells(20).Value?.ToString = "12" Then
c = 0
d = 0
Try
d = dgvBillItems.Rows.Count
For c = 0 To dgvBillItems.Rows.Count - 1
tot2 += Convert.ToDouble(dgvBillItems.Rows(c).Cells(4).Value)
Next c
Catch ex As Exception
MsgBox(ex.Message)
End Try
txtTaxVal12.Text = tot2
End If
If dgvBillItems.Rows(i).Cells(20).Value?.ToString = "18" Then
e = 0
f = 0
Try
f = dgvBillItems.Rows.Count
For e = 0 To dgvBillItems.Rows.Count - 1
tot2 += Convert.ToDouble(dgvBillItems.Rows(e).Cells(4).Value)
Next e
Catch ex As Exception
MsgBox(ex.Message)
End Try
txtTaxVal18.Text = tot3
End If
Next
End Function