Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all
My name is Sarfaraz and I have started developing a project in VB.Net and Access. After completing my main form i am stuck on my next form because:
I have a combo box which is populated from access database table and selecting an item from the combo box, the list box gets filled with different options.
I want to select some options from the list box and they should be displayed like a table where against each selected item i should be able to add manually the quantity needed and accordingly the total price should be displayed and finally should print that.
It is something like a POS where against each item you have quantity, rate and total price displayed

I am actually stuck what control to use for this Listview or gridview. Please help me in that.
Thank you
Posted
Updated 5-Dec-14 3:12am
v2

1 solution

Hi,

Gridview is better option.

Take four column as 1st item_name,2nd quantity,3rd rate and 4th total

after selected list item you can bind the selected item to gridview
with item_name and other column as blank.

according to selection row will generated then you can manually entry
quantity,rate and total.
 
Share this answer
 
Comments
sarfarazbhat 13-Dec-14 23:16pm    
Thank you mudgilsks for your kind help, I did that and now i have a small issue in that I just wanted to enter length and breadth and amount (that is length * breadth * rate) should be displayed on the last cell of gridview. The code is like
If DataGridView1.Rows.Count > 0 Then
DataGridView2.Rows.Add(DataGridView1.CurrentRow.Cells(0).Value, DataGridView1.CurrentRow.Cells(1).Value, DataGridView1.CurrentRow.Cells(2).Value)
End If
Than you
sarfarazbhat 14-Dec-14 1:24am    
I tried little further with below code and it is doing exactly what i wanted but the problem is that it is calculating the selected row and i wanted all the calculations for all the rows.
Try

Dim iCell2 As Integer
Dim icell3 As Integer
Dim icell4 As Integer
Dim icellResult As Integer
' Dim icellResult As Integer
iCell2 = DataGridView2.CurrentRow.Cells(2).Value
icell3 = DataGridView2.CurrentRow.Cells(3).Value
icell4 = DataGridView2.CurrentRow.Cells(4).Value
If String.IsNullOrEmpty(iCell2) OrElse String.IsNullOrEmpty(icell3) OrElse String.IsNullOrEmpty(icell4) Then Exit Sub
If Not IsNumeric(iCell2) OrElse Not IsNumeric(icell3) OrElse Not IsNumeric(icell4) Then Exit Sub
icellResult = CDbl(iCell2) * CDbl(icell3) * CDbl(icell4)
DataGridView2.CurrentRow.Cells(5).Value = icellResult

Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
I think it needs a loop to count the number of datagridview rows.
pls give some guidance.
Thank you
mudgilsks 15-Dec-14 1:41am    
hi,

right, use for loop for each row of the grid view.
after that if you face problem,you can mail your page on:mudgilsks@gmail.com
after checking i will resend back to you.
sarfarazbhat 15-Dec-14 12:01pm    
Thank you for your kind help
I tried the following code and it worked nicely:
Try
Dim iCell2 As Integer
Dim icell3 As Integer
Dim icell4 As Integer
Dim icellResult As Integer
Dim i As Integer
For i = 0 To DataGridView2.Rows.Count - 1
'MsgBox(DataGridView1.SelectedRows.Count)
' Dim icellResult As Integer
iCell2 = DataGridView2.Rows(i).Cells(2).Value
icell3 = DataGridView2.Rows(i).Cells(3).Value
icell4 = DataGridView2.Rows(i).Cells(4).Value
If String.IsNullOrEmpty(iCell2) OrElse String.IsNullOrEmpty(icell3) OrElse String.IsNullOrEmpty(icell4) Then Exit Sub
If Not IsNumeric(iCell2) OrElse Not IsNumeric(icell3) OrElse Not IsNumeric(icell4) Then Exit Sub
icellResult = CDbl(iCell2) * CDbl(icell3) * CDbl(icell4)
DataGridView2.Rows(i).Cells(5).Value = icellResult
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900