Hi my name is Ade and I have a question in VB.net, in the project are the following, form1, form2, and module 1, below is fair representation of a datagrid am working which is located in form1
---------------------------------------------
id |quantity | item | cost | idtype |
-------------------------------------------------
1 | 1 | shirt | 200 | G |
--------------------------------------------------
2 | 0 | blue | 0 | C. |
--------------------------------------------------
3 | 0 | cotton. | 0 | M |
--------------------------------------------------
4. | 0 |press only. | -100 | E |
--------------------------------------------------
5 | 0 | children | -50 | E |
--------------------------------------------------
when I click a button on this form another form appears bearing the cell values in column 2(item column) in the datagridview on another form, form2. Form2 has label controls on which each of these values are assigned to, below is the code:
Module
Module1
Public taggarmentname as string
Public taggarmentcost as integer
Public taggarmentcolor as string
Public taggarmentfabric as string
End Module
On form1
Private sub btndisplay_click
For r as integer = 0 To hdgvlaundry.rows.count -1
If hdgvlaundry.rows(r).cells(4).value ="G" then
Taggarmentname= hdgvlaundry.rows(r).cells(2).value
Taggarmentcost=hdgvlaundry.rows(r).cells(3).value
Elseif hdgvlaundry.rows(r).cells(4).value ="C" then
Taggarmentcolor = hdgvlaundry.rows(r).cells(2).value
Elseif hdgvlaundry.rows(r).cells(4).value ="M" then
Taggarmentfabric = hdgvlaundry.rows(r).cells(2).value
Form2.show dialog
Endif
Next
End sub
On form2
Private sub form2_load
Lblgarmentnametag.text= taggarmentname
Lblgarmentpricetag.text= taggarmentcost
Lblgarmenttagcolor.text= taggarmentcolor
Lblgarmenttagfabric.text= taggarment
End sub
All this works well, the issue is that I do not know how to store the value in column 2 which has its idtype column(4) equal to value "E" which appears twice.
what I mean is that I wish to store the values 'press only' and 'children' in one string variable and have it displayed in a label on form2 as follows:
'press only/children'.
The other rows always have their idtype column(4) distinct, that is appearing once, but sometimes the row with a idtype column(4) equal to 'E' may appear more than once, hence the need to store multiple cell values of column(2) with idtype column(4) of value 'E' in a variable. Please can someone help.
In my code on form1, to store the cell value on column 2 (item column) I use the condition statement:
For r as integer = 0 To hdgvlaundry.rows.count -1
If hdgvlaundry.rows(r).cells(4).value ="G" then
Taggarmentname= hdgvlaundry.rows(r).cells(2).value
Taggarmentcost=hdgvlaundry.rows(r).cells(3).value
Now this is easy and straight forward because the idtype column (column 4) with value = 'G' appears only once.
So also is idtype column (column 4) with value = 'C' which also appears only once :
Elseif hdgvlaundry.rows(r).cells(4).value ="C" then
Taggarmentcolor = hdgvlaundry.rows(r).cells(2).value
Similarly is the case for idtype column (column 4) with value = 'M' which also appears only once
Elseif hdgvlaundry.rows(r).cells(4).value ="M" then
Taggarmentfabric = hdgvlaundry.rows(r).cells(2).value
But for idtype column (column 4) with value = 'E' it appears more than once (2 times) and the corresponding item column (Column 2) has 2 values('press only' and 'children'), which I need to store, both in a variable. So how do I store both cellvalues of 2 different rows in a variable
Kind regards
Ade
[Comment]Use proper formatting![/Comment]