locked
Favourites of a Web Browser in Settings String Collection displayed into Toolstripmenuitem list RRS feed

  • Question

  •  I have indded found the similar topics already in exisitance on these forums. i have even used them to create my favourites. i tried to add this a post on a thread but it had been ticked as answered so i thought it wouldnt recieve any attention. anyways.

    i have failed to get the code to work. when i run my program, the FormWebBrowser_load event occours, and it begins to load the following code:

    Private Sub FormWebBrowser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     
            WebBrowser.Navigate(My.Settings.HomePage)     
        
            For Each item As String In My.Settings.favList     
                Dim item1 As New ToolStripMenuItem     
                item item1.Text = item.ToString     
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)     
            Next     
        
            For Each C As ToolStripMenuItem In FavouritesToolStripMenuItem.DropDownItems     
                AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click     
            Next     
        
        End Sub    
     

    The error that occours looks like the following:

    Private Sub FluidWebBrowser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            WebBrowser.Navigate(My.Settings.HomePage)  
     
            For Each item As String In My.Settings.favList  
                Dim item1 As New ToolStripMenuItem  
                item item1.Text = item.ToString  
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)  
            Next  
     
            For Each C As ToolStripMenuItem In FavouritesToolStripMenuItem.DropDownItems  
                AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click  
            Next  
     
        End Sub 

    The highlighted text is given the following error code:

    Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.

    if anyone can explain this, i would be greatful!

    cheers, nick

    EDIT: first use of these forums, what is the deal with the red and blue highlighting in my code windows? is it highlighting a mistake in my code? because that part of the code runs fine...

    also, from my understanding, this piece of code creates the click action for all favourites in the toolstripmenuitem object. i have commented them out and the program runs but no click will do anything. however the code stops the program at startup with it as explained above.

    www.makeshiftfilms.com.au
    • Edited by nicky g Thursday, October 23, 2008 5:45 AM new ideas/info
    Thursday, October 23, 2008 5:43 AM

Answers

  • nicky g said:

    The error that occours looks like the following:

    Private Sub FluidWebBrowser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            WebBrowser.Navigate(My.Settings.HomePage)  
     
            For Each item As String In My.Settings.favList  
                Dim item1 As New ToolStripMenuItem  
                item item1.Text = item.ToString  
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)  
            Next  
     
            For Each C As ToolStripMenuItem In FavouritesToolStripMenuItem.DropDownItems  
                AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click  
            Next  
     
        End Sub 

    The highlighted text is given the following error code:
    Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.


    Hi nicky,

    Here is modified code sample.
        Private Sub FluidWebBrowser_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
     
            WebBrowser.Navigate(My.Settings.HomePage)  
     
            ' Load Settings to Favorites menu when opening form  
            For Each item As String In My.Settings.favList  
                Dim item1 As New ToolStripMenuItem  
                item1.Text = item.ToString  
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)  
            Next 
     
            'Add Click Event handler for each Favorite link ToolStripMenuItem     
            For Each C As ToolStripItem In FavouritesToolStripMenuItem.DropDownItems  
                If TypeOf (C) Is ToolStripMenuItem Then 'Exclude ToolStripSeparator items   
                    AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click  
                End If 
            Next 
     
        End Sub 

    Trackback to this thread for detail code sample:
    http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/46729475-ffc5-4666-b4d0-f0d162a49acc



    If you feel interested, please leave your email, I'd like to send my sample project to you for checking.
    v-maxie@microsoft.com

    Best regards,
    Martin Xie
    Thursday, October 30, 2008 5:23 AM

All replies

  • nicky g said:

    The error that occours looks like the following:

    Private Sub FluidWebBrowser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            WebBrowser.Navigate(My.Settings.HomePage)  
     
            For Each item As String In My.Settings.favList  
                Dim item1 As New ToolStripMenuItem  
                item item1.Text = item.ToString  
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)  
            Next  
     
            For Each C As ToolStripMenuItem In FavouritesToolStripMenuItem.DropDownItems  
                AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click  
            Next  
     
        End Sub 

    The highlighted text is given the following error code:
    Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.


    Hi nicky,

    Here is modified code sample.
        Private Sub FluidWebBrowser_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
     
            WebBrowser.Navigate(My.Settings.HomePage)  
     
            ' Load Settings to Favorites menu when opening form  
            For Each item As String In My.Settings.favList  
                Dim item1 As New ToolStripMenuItem  
                item1.Text = item.ToString  
                FavouritesToolStripMenuItem.DropDownItems.Add(item1)  
            Next 
     
            'Add Click Event handler for each Favorite link ToolStripMenuItem     
            For Each C As ToolStripItem In FavouritesToolStripMenuItem.DropDownItems  
                If TypeOf (C) Is ToolStripMenuItem Then 'Exclude ToolStripSeparator items   
                    AddHandler C.Click, AddressOf FavouritesToolStripMenuItem_Click  
                End If 
            Next 
     
        End Sub 

    Trackback to this thread for detail code sample:
    http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/46729475-ffc5-4666-b4d0-f0d162a49acc



    If you feel interested, please leave your email, I'd like to send my sample project to you for checking.
    v-maxie@microsoft.com

    Best regards,
    Martin Xie
    Thursday, October 30, 2008 5:23 AM
  • Dear Martin Xie , MicroSoft 

    I have loocked at your code and im stunned , and I also thanks you for helping me adding my own favourites button but, I was wondering , instead of having the URL adresses could it be possible to have for an example take Microsoft : What Im meaning is this, Instead of :
    http://www.microsoft.com it will change to "MicroSoft Corporation"... Is this possibe ?

    Thanks For Your Time :-)

    SlSystems
    Saturday, January 24, 2009 1:55 AM
  • Strasios Inc said:

    I have loocked at your code and im stunned , and I also thanks you for helping me adding my own favourites button but, I was wondering, instead of having the URL adresses, could it be possible to have for an example take Microsoft: What Im meaning is this, Instead of:
    http://www.microsoft.com it will change to "Microsoft Corporation"... Is this possibe?

    Hi Strasios,

    Sorry for the delay due to my annual leave during Chinese Spring Festival.

    I understand you. You want to hide link URL in background and show link title at foreground. The key is: you can use System.Collections.HashTable data type instead of System.Collections.Specialized.StringCollection via My.Settings in VB.NET.
    Project menu-> Properties -> Settings tab
    Name   linkHashTable
    Type  
    System.Collections.HashTable (Browser and locate this type)
    Scope    User      

    PLease check the following threads for related walkthrough:

    1) Favorites feature example

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/46729475-ffc5-4666-b4d0-f0d162a49acc
    2) HashTable example
    http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/7cfbe759-3e04-498f-b013-a879770ae85f/


    The primary ideas:
    1) The HashTable object can be used to store multiple Key-Value pairs like this: 

         linkHashTable.Add("LinkTitle", "LinkURL")

    2) Retrieve LinkURL:  WebBrowser1.Url.ToString
        Retrieve LinkTitle:  WebBrowser1.DocumentTitle.ToString

    3) Retrieve LinkURL according to LinkTitle:
        LinkURL = linkHashTable(LinkTitle)

         

    Best regards,
    Martin Xie

    Wednesday, February 4, 2009 4:20 AM