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.

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.

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).............................................
................................

end quote.

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.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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
This question has already been answered. Start a new discussion instead.