3 Replies - 846 Views - Last Post: 24 September 2015 - 06:21 AM Rate Topic: -----

#1 mabs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-September 15

how to store multiple cell values in a datagrid column in a variable

Posted 21 September 2015 - 10:49 AM

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| it | 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/displaying the cell values in column 2(item column) in the datagridview in label controls in another form, form2. Form2 has label controls on which each of these values are assigned to, below is the code:

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®.cells(4).value ="G" then
Taggarmentname= hdgvlaundry.rows®.cells(2).value
Taggarmentcost=hdgvlaundry.rows®.cells(3).value

Elseif hdgvlaundry.rows®.cells(4).value ="C" then
Taggarmentcolor = hdgvlaundry.rows®.cells(2).value

Elseif hdgvlaundry.rows®.cells(4).value ="M" then
Taggarmentfabric = hdgvlaundry.rows®.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,like twice or thrice 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®.cells(4).value ="G" then
Taggarmentname= hdgvlaundry.rows®.cells(2).value
Taggarmentcost=hdgvlaundry.rows®.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®.cells(4).value ="C" then
Taggarmentcolor = hdgvlaundry.rows®.cells(2).value

Similarly is the case for idtype column (column 4) with value = 'M' which also appears only once



Elseif hdgvlaundry.rows®.cells(4).value ="M" then
Taggarmentfabric = hdgvlaundry.rows®.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

Permit me to explain a little further;

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®.cells(4).value ="G" then
Taggarmentname= hdgvlaundry.rows®.cells(2).value
Taggarmentcost=hdgvlaundry.rows®.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®.cells(4).value ="C" then
Taggarmentcolor = hdgvlaundry.rows®.cells(2).value

Similarly is the case for idtype column (column 4) with value = 'M' which also appears only once

Elseif hdgvlaundry.rows®.cells(4).value ="M" then
Taggarmentfabric = hdgvlaundry.rows®.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

Is This A Good Question/Topic? 0
  • +

Replies To: how to store multiple cell values in a datagrid column in a variable

#2 sam.ganjavi  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 75
  • Joined: 03-September 15

Re: how to store multiple cell values in a datagrid column in a variable

Posted 21 September 2015 - 11:20 AM

Hi

If I understand correctly You just have to add the value to an existing variable. something like
   if NOT myVariable.lenght= 0 then myVariable+= "/"  'insert a seperator
   myVariable += myNewValue 'add a new value to the variable


Was This Post Helpful? 0
  • +
  • -

#3 mabs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-September 15

Re: how to store multiple cell values in a datagrid column in a variable

Posted 23 September 2015 - 01:58 PM

View Postsam.ganjavi, on 21 September 2015 - 11:20 AM, said:

Hi

If I understand correctly You just have to add the value to an existing variable. something like
   if NOT myVariable.lenght= 0 then myVariable+= "/"  'insert a seperator
   myVariable += myNewValue 'add a new value to the variable



Hi Sam thanks, sorry am replying quite late, thanks for the reply, but am not quite sure you understand what the challenge is, you see I have rows each added to the datagrid and three of these row occur once and they are distinct in that their idtype appears once: "G" , "C", "M" , which makes it easy to assign their values in column 2 (the item column) to a variable, but I have a particular row with idtype E which oftens occurs twice or more now I need to add values of column2 (item column), with idtype "E" which occurs more than once into the variable. I tried the code you sent but its not just solving it only picks the first cell value with idtype E, ignoring the second cell value of idtype "E". So what do you think?
Was This Post Helpful? 0
  • +
  • -

#4 sam.ganjavi  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 75
  • Joined: 03-September 15

Re: how to store multiple cell values in a datagrid column in a variable

Posted 24 September 2015 - 06:21 AM

View Postmabs, on 23 September 2015 - 03:58 PM, said:

View Postsam.ganjavi, on 21 September 2015 - 11:20 AM, said:

Hi

If I understand correctly You just have to add the value to an existing variable. something like
   if NOT myVariable.lenght= 0 then myVariable+= "/"  'insert a seperator
   myVariable += myNewValue 'add a new value to the variable



Hi Sam thanks, sorry am replying quite late, thanks for the reply, but am not quite sure you understand what the challenge is, you see I have rows each added to the datagrid and three of these row occur once and they are distinct in that their idtype appears once: "G" , "C", "M" , which makes it easy to assign their values in column 2 (the item column) to a variable, but I have a particular row with idtype E which oftens occurs twice or more now I need to add values of column2 (item column), with idtype "E" which occurs more than once into the variable. I tried the code you sent but its not just solving it only picks the first cell value with idtype E, ignoring the second cell value of idtype "E". So what do you think?


WHen you debug your code what does it do exactly? are you sure it reads the line and if it will process it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1