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.

Recommended Answers

All 3 Replies

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.