DataGridView integer problem?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2007
Posts: 11
Reputation: Fritzeh is an unknown quantity at this point 
Solved Threads: 0
Fritzeh Fritzeh is offline Offline
Newbie Poster

DataGridView integer problem?

 
0
  #1
Apr 7th, 2008
Hey people, I'm not sure what is wrong with this code and any help would be greatly appreciated:

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim i As Integer = DGVShops.CurrentRow.Index
  3. Dim c As Integer = DGVShops.Item(0, i).Value ' gets value from selected rows first column
  4. Dim s As String = DGVShops.Item(2, i).Value ' gets a string which is the name (3rd column)
  5.  
  6. ShowMe(c, s) ' passes parameters
  7.  
  8. End Sub
  9.  
  10. Private Sub ShowMe(ByVal c, ByVal s)
  11. Select Case c ' which should be an integer...
  12. Case 1 To 46
  13. label.Text = (s + " some text " + c)
  14. End Select
  15. End Sub

I dont think it is passed as a value... although when I used .tostring i managed to get the interger shown.
Last edited by Fritzeh; Apr 7th, 2008 at 5:23 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 169
Reputation: ptaylor965 is an unknown quantity at this point 
Solved Threads: 19
Sponsor
ptaylor965's Avatar
ptaylor965 ptaylor965 is offline Offline
Junior Poster

Re: DataGridView integer problem?

 
0
  #2
Apr 7th, 2008
Where is the problem?

If the problem is with
  1. Dim c As Integer = DGVShops.Item(0, i).Value
Then try using CType
  1. Dim c As Integer = CType(DGVShops.Item(0, i).Value, Integer)
If the problem is the table returning a string and not an integer then this should fix it.
Last edited by ptaylor965; Apr 7th, 2008 at 7:57 pm.
Peter Taylor
Visual Basic.NET Application Developer

TaylorsNet
http://www.taylorsnet.co.uk
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: DataGridView integer problem?

 
0
  #3
Apr 8th, 2008
Originally Posted by Fritzeh View Post
Hey people, I'm not sure what is wrong with this code and any help would be greatly appreciated:

[CODE]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = DGVShops.CurrentRow.Index
Dim c As Integer = DGVShops.Item(0, i).Value ' gets value from selected rows first column
Dim s As String = DGVShops.Item(2, i).Value ' gets a string which is the name (3rd column)
.............................................
................................

hi

i think the problem is while fetching the grid value this should be like this...
variable = datagrid1.Item(datagrid1.CurrentRowIndex, 0) ' this will give u current rows 0th column value
like wise.

check this.

Best luck.
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 11
Reputation: Fritzeh is an unknown quantity at this point 
Solved Threads: 0
Fritzeh Fritzeh is offline Offline
Newbie Poster

Re: DataGridView integer problem?

 
0
  #4
Apr 8th, 2008
Thanks for your suggestions but I fixed the code by changing the integer to a string, I think Select Case didn't like the integer for some reason?

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim i As Integer = DGVShops.CurrentRow.Index
  3. Dim c As Integer = DGVShops.Item(0, i).Value ' gets value from selected rows first column
  4. Dim s As String = DGVShops.Item(2, i).Value ' gets a string which is the name (3rd column)
  5.  
  6. ShowMe(c, s) ' passes parameters
  7.  
  8. End Sub
  9.  
  10. Private Sub ShowMe(ByVal c, ByVal s)
  11. Select Case c ' which should be an integer...
  12. Case 1 To 46
  13. label.Text = (s + " some text " + c)
  14. End Select
  15. End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  16. Dim i As Integer = DGVShops.CurrentRow.Index
  17. Dim c As string= DGVShops.Item(0, i).Value ' gets value from selected rows first column
  18. Dim s As String = DGVShops.Item(2, i).Value ' gets a string which is the name (3rd column)
  19.  
  20. ShowMe(c, s) ' passes parameters
  21.  
  22. End Sub
  23.  
  24. Private Sub ShowMe(ByVal c, ByVal s)
  25. Select Case c ' which should be an integer...
  26. Case 1 To 46
  27. label.Text = (s + " some text " + c)
  28. End Select
  29. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC