Selecting Datagridview cell data in reference to row index

DexterGene

New member
Joined
Aug 6, 2011
Messages
1
Programming Experience
1-3
I've been looking everywhere for an answer to a simple question, but i'm having issues, so i thought i'd join and post here.
I'm having issues with a simple concept. I load information from a SQL database, and i want to add a 'Passport' link URL relating to column cells called 'name'. It basically selects the name, and inserts it into the link fields to be opened. But i cant find a way to work it.
I thought i could do it with something like:
VB.NET:
Public Shared Sub retriveDataToDataGrid()        
Dim names() As String
        Try
            Dim lnk As New DataGridViewLinkColumn()
            Dim query As String = "SELECT * FROM data"
            Dim connection As New MySqlConnection(connStr)
            Dim da As New MySqlDataAdapter(query, connection)
            Dim ds As New DataSet()
            If da.Fill(ds) Then
                Form2.DataGridView1.DataSource = ds.Tables(0)
                Form2.DataGridView1.Columns.Add(lnk)
                For x = 0 To Form2.DataGridView1.Rows.Count - 1
                    names(x) = Convert.ToString(Form2.DataGridView1.Item(2, x).Value)
                    lnk.Text = "C:\" & names(x)".jpg"
                Next x
                lnk.HeaderText = "Passport"
                lnk.UseColumnTextForLinkValue = True
            End If
            connection.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

But i thought wrong and i'm getting null exceptions from the loop.
How could i do this (is there another way)?
Thanks for help in advance.
 
Last edited:
If this is copied from your code, I found a syntax error at this line:

lnk.Text = "C:\" & names(x)".jpg"

It should be: lnk.Text = "C:\" & names(x) & ".jpg"
 
Back
Top