943,862 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2175
  • VB.NET RSS
Apr 7th, 2008
0

DataGridView integer problem?

Expand Post »
Hey people, I'm not sure what is wrong with this code and any help would be greatly appreciated:

VB.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Fritzeh is offline Offline
11 posts
since Apr 2007
Apr 7th, 2008
0

Re: DataGridView integer problem?

Where is the problem?

If the problem is with
VB.NET Syntax (Toggle Plain Text)
  1. Dim c As Integer = DGVShops.Item(0, i).Value
Then try using CType
VB.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Apr 8th, 2008
0

Re: DataGridView integer problem?

Click to Expand / Collapse  Quote originally posted by Fritzeh ...
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.
sbv
Reputation Points: 15
Solved Threads: 8
Junior Poster
sbv is offline Offline
178 posts
since Jan 2008
Apr 8th, 2008
0

Re: DataGridView integer problem?

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?

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Fritzeh is offline Offline
11 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Snapping Forms together
Next Thread in VB.NET Forum Timeline: .Net Battler Needing help Desperately lol!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC