hellow and hi! i am working on billing system first i want to define purpose of bellow code this code will multiply the qty and price and assign the value to total column and validated on enter key if i press enter key and value is price or qty is null it will show the message. up to this it works fine but trouble i have face here is that suppose when user enter the value in qty column and value in price column but user is not going to press the enter key and got new row by press arrow key or press tab or by clicking the mouse then. total columns remain null so how it can be achive that if total column is empty then user can't go to new line or row in datagrid.
and second problem is that when i click row of datagridview to enter data then new row is automatically inserted in datagrid.
idea that i have is that when i enter the data in grid by clicking and editing the row then new row is not inserted but it must be inserted on enter key event and in the enter key even i will make validation that if total Column is empty then it should not insert new row thxxxxxx in advance
Private Sub DgvBill_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DgvBill.KeyUp
Try
Dim qty As Integer = 0
Dim price As Integer = 0
Dim total As Integer = 0
If e.KeyCode = Keys.Enter Then
For j = 0 To DgvBill.RowCount - 2
If DgvBill.Item("ClmQty", j).Value = "" Then
MsgBox("PLEASE ENTER QTY VALUE")
Return
End If
If DgvBill.Item("ClmPrice", j).Value = "" Then
MsgBox("PLEASE ENTER PRICE VALUE")
Return
End If
qty = CInt(DgvBill.Item("ClmQty", j).Value.ToString)
price = CInt(DgvBill.Item("ClmPrice", j).Value.ToString)
total = qty * price
DgvBill.Item("ClmTotal", j).Value = total
Next
End If
'qty = CInt(DataGridView1.Rows(0).Cells(1).Value.ToString)
'price = CInt(DataGridView1.Rows(0).Cells(2).Value.ToString)
'total = qty * price
'DataGridView1.Rows(0).Cells(3).Value = total
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub