Results 1 to 2 of 2

Thread: Datagrid >> XML >> Website Hyperlink

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Datagrid >> XML >> Website Hyperlink

    I have a datagrid that connect to my xml file and displays 3 columns of data, the third which is the website links, how can I have it so those website links become hyperlinks, can someone assist me with this please:

    Code:
    Imports System.Xml
    Imports System.Data
    
    Public Class Form1
    
        Dim ds As New DataSet
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim xmlFile As XmlReader
            xmlFile = XmlReader.Create("C:\Projects\Grid Search Application\PhoneData.xml", New XmlReaderSettings())
    
            ds.ReadXml(xmlFile)
    
            DataGridView1.DataSource = ds.Tables(0)
    
        End Sub
    
        Private Sub btnMobileDeviceFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMobileDeviceFilter.Click
            ds.Tables(0).DefaultView.RowFilter = "[Mobile_Phone_Type] like '%" & tbMobileDevice.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
    
        Private Sub btnSimType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimType.Click
            ds.Tables(0).DefaultView.RowFilter = "[SIM_Type] like '%" & tbSIMType.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
    
        Private Sub btnWebsiteLinkFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWebsiteLinkFilter.Click
            ds.Tables(0).DefaultView.RowFilter = "[Website_Link] like '%" & tbWebsiteLink.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
    Everything runs smoothly, I just want to make the website links hyperlinks.

    Can I use this in my code?

    http://www.vbforums.com/showthread.p...ight=hyperlink

    Thank you.
    Last edited by jokerfool; Feb 23rd, 2013 at 07:36 AM.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Datagrid >> XML >> Website Hyperlink

    The trick is to create your datagridview columns before binding the table and specifying their data member ...

    vb.net Code:
    1. Dim dt As New DataTable
    2.         dt.Columns.Add("Links", GetType(String))
    3.         dt.Rows.Add({"http://www.google.co.uk"})
    4.         dgv.Columns.Add(New DataGridViewLinkColumn)
    5.         dgv.Columns(0).DataPropertyName = "Links"
    6.         dgv.Columns(0).Name = "Links"
    7.         dgv.DataSource = dt

    Don't forget though that this only gives the appearance of a hyperlink. As with link labels you still need to program the result of a click eg. launching a browser.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width