-
VB.NET (
http://www.daniweb.com/forums/forum58.html)
| Fritzeh | Apr 7th, 2008 5:20 pm | |
| DataGridView integer problem? Hey people, I'm not sure what is wrong with this code and any help would be greatly appreciated:
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)
ShowMe(c, s) ' passes parameters
End Sub
Private Sub ShowMe(ByVal c, ByVal s)
Select Case c ' which should be an integer...
Case 1 To 46
label.Text = (s + " some text " + c)
End Select
End Sub
I dont think it is passed as a value... although when I used .tostring i managed to get the interger shown. |
| ptaylor965 | Apr 7th, 2008 7:57 pm | |
| Re: DataGridView integer problem? Where is the problem?
If the problem is with Dim c As Integer = DGVShops.Item(0, i).Value Then try using CType 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. |
| sbv | Apr 8th, 2008 6:10 am | |
| Re: DataGridView integer problem? Quote: Originally Posted by Fritzeh (Post 579518) 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. |
| Fritzeh | Apr 8th, 2008 10:08 am | |
| 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?
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)
ShowMe(c, s) ' passes parameters
End Sub
Private Sub ShowMe(ByVal c, ByVal s)
Select Case c ' which should be an integer...
Case 1 To 46
label.Text = (s + " some text " + c)
End Select
End SubPrivate 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 string= 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)
ShowMe(c, s) ' passes parameters
End Sub
Private Sub ShowMe(ByVal c, ByVal s)
Select Case c ' which should be an integer...
Case 1 To 46
label.Text = (s + " some text " + c)
End Select
End Sub |
| All times are GMT -4. The time now is 6:32 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC