I need to add the URL property to webbrowser1 (located on my form) from a dataset containing the URL, but am getting the error "Invalid cast from 'System.String' to 'System.Uri'. The column in datagridview1 is called link. I need the web browser URL to change with a corresponding textbox and listbox. I have the code correct on the listbox and textbox, as to when an item in the listbox is clicked the textbox changes. I need the webbrowser to change along with them. Here's what I have so far.

Public Shared Function loadRSSfeeds()
        'create dataset to hold data from XML 
        Dim ds As DataSet = New DataSet
        'clear listbox upon refreshing feed


        'fill DGV with data
        MainForm.DataGridView1.DataSource = ds.Tables("item")
        'add items from XML files to listbox

        MainForm.articleListBox.DataSource = ds.Tables("item")
        MainForm.articleListBox.DisplayMember = "title"
        MainForm.articleListBox.ValueMember = "title"

        'add description from selected news article to textbox
        MainForm.descritptionListBox.DataBindings.Add("Text", ds.Tables("item"), "description")

        'add URL to web browser corresponding to selected article and description
        MainForm.WebBrowser1.DataBindings.Add("Url", ds.Tables("item"), "link")
        'I get the error "Invalid cast from 'System.String' to 'System.Uri'."

    End Function

Recommended Answers

All 3 Replies

Try changing: MainForm.WebBrowser1.DataBindings.Add("Url", ds.Tables("item"), "link")

To: MainForm.WebBrowser1.DataBindings.Add("Url", ds.Tables("item"), "link", True)

This enables formatting of the value which invokes the property's TypeConverter.

That absoluetly worked. Thank you for your help.

Be a part of the DaniWeb community

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