Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Might be a stupid question but...

Might be a stupid question but...

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiotutorialquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darshon
    wrote on last edited by
    #1

    I just can't seem to wrap my brain around this one. (Yes I'm a Newbei, lol) I just don't understand how to click on a list item and get it to do what I want. I've got a listview control that shows "*.url" files and I'd like the user to click on the list item (*.url) and get it to open in the WebBrowser control that's on the same form. How would I go about doing that. I'm using VS.Net 2003.

    D 1 Reply Last reply
    0
    • D Darshon

      I just can't seem to wrap my brain around this one. (Yes I'm a Newbei, lol) I just don't understand how to click on a list item and get it to do what I want. I've got a listview control that shows "*.url" files and I'd like the user to click on the list item (*.url) and get it to open in the WebBrowser control that's on the same form. How would I go about doing that. I'm using VS.Net 2003.

      D Offline
      D Offline
      Dean_SF
      wrote on last edited by
      #2

      In the SelectedIndexChanged event for the listview: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).SubItems(1).Text) This is assuming the URL is in the second column of the listview. If the URL is in the first column of the listview: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).Text) Dean

      D 1 Reply Last reply
      0
      • D Dean_SF

        In the SelectedIndexChanged event for the listview: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).SubItems(1).Text) This is assuming the URL is in the second column of the listview. If the URL is in the first column of the listview: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).Text) Dean

        D Offline
        D Offline
        Darshon
        wrote on last edited by
        #3

        Hello Dean, Thank you for that code. :-) It does work except it gives me the text of the item name as the navigating address which does not work. You have helped me though to realize that I must find a way to open the url file referrenced by that ListItem name in order to read it and then send the "http://" text within that file to the WebBrowser.Navigate. If you or anyone else can help me out to do this or maybe direct me in the right dirrection to figure it out, that would be great. Thanks again for your help.

        D 1 Reply Last reply
        0
        • D Darshon

          Hello Dean, Thank you for that code. :-) It does work except it gives me the text of the item name as the navigating address which does not work. You have helped me though to realize that I must find a way to open the url file referrenced by that ListItem name in order to read it and then send the "http://" text within that file to the WebBrowser.Navigate. If you or anyone else can help me out to do this or maybe direct me in the right dirrection to figure it out, that would be great. Thanks again for your help.

          D Offline
          D Offline
          Dean_SF
          wrote on last edited by
          #4

          So what exactly is in the listview? Is it at list of URLS like this: http://www.codeproject.com http://www.msn.com http://www.google.com . . . etc? Or does the list contain the name of each website like this: CodeProject MSN Google . . . etc? Thanks, Dean

          D 1 Reply Last reply
          0
          • D Dean_SF

            So what exactly is in the listview? Is it at list of URLS like this: http://www.codeproject.com http://www.msn.com http://www.google.com . . . etc? Or does the list contain the name of each website like this: CodeProject MSN Google . . . etc? Thanks, Dean

            D Offline
            D Offline
            Darshon
            wrote on last edited by
            #5

            It gets the name of the url files like this. 1sitename.url 2sitename.url

            D 1 Reply Last reply
            0
            • D Darshon

              It gets the name of the url files like this. 1sitename.url 2sitename.url

              D Offline
              D Offline
              Dean_SF
              wrote on last edited by
              #6

              In that case, what I would do is put the actual URL navigation text in another hidden column of your listview and reference that text for the Navigate command. So where the users see: 1sitename.url 2sitename.url ...listed in the first column of the listview, in the second column (with a column width of zero) would be the URL navigation text: http://www.1sitename.com http://www.2sitename.com Then in the SelectedIndexChanged event you could do your navigate: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).SubItems(1).Text) Dean

              D 1 Reply Last reply
              0
              • D Dean_SF

                In that case, what I would do is put the actual URL navigation text in another hidden column of your listview and reference that text for the Navigate command. So where the users see: 1sitename.url 2sitename.url ...listed in the first column of the listview, in the second column (with a column width of zero) would be the URL navigation text: http://www.1sitename.com http://www.2sitename.com Then in the SelectedIndexChanged event you could do your navigate: Me.WebBrowser1.Navigate(Me.lvwLeft.SelectedItems(0).SubItems(1).Text) Dean

                D Offline
                D Offline
                Darshon
                wrote on last edited by
                #7

                so each file in the directory I look through to populate the ListView I would need to open/read it and then put it's http address text in a hidden column in the Listview. That's what you mean right? Question: If so, wouldn't that make things lag quite a bit if a person has many folders with possible 100's of links in it? Thanks -- modified at 17:56 Friday 24th February, 2006

                D 1 Reply Last reply
                0
                • D Darshon

                  so each file in the directory I look through to populate the ListView I would need to open/read it and then put it's http address text in a hidden column in the Listview. That's what you mean right? Question: If so, wouldn't that make things lag quite a bit if a person has many folders with possible 100's of links in it? Thanks -- modified at 17:56 Friday 24th February, 2006

                  D Offline
                  D Offline
                  Darshon
                  wrote on last edited by
                  #8

                  Hey Dean, I did what you suggested and it works very nicely and it doesn't lag at all. At least not with my Favorites folder and I have quite a few links in there. ;-) The only problem I have now is that I have only been able to read the complete url file text and there is too much garbage text to send it as a http: address. I have to find a way to extract only the url text and put that in the hidden column. Any ideas? Thanks :-) The text I get from the StreamReader is simular to this for every url file it reads, just the actual http:// text changes. "[default]baseurl=http://www.adenak.com/\[InternetShortcut\]URL=http://www.adenak.com/Modified=1067F49A2E3BC50134" Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect 'Get reference to the selected node Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath) 'Clear all the items in the listview lvwExplorer.Items.Clear() 'Check if the Directory exist or not If (dirInfo.Exists) Then 'Get reference to all the files Dim fileInfos As FileInfo() = dirInfo.GetFiles() 'Add all the files to the ListView one by one Dim info As FileInfo For Each info In fileInfos 'First check the extension, make sure it's a url file If info.Extension = ".url" Then Try 'Open the file and read it 'Convert the file path into a string for the StreamReader Dim infoPath As String = info.FullName ' Create an instance of StreamReader to read from each file. Dim sr As StreamReader = New StreamReader(infoPath) 'Read the complete url file text Dim url As String url = sr.ReadToEnd() 'Extract only the url text **This is where I need to extract the http text** Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name) ' Link the ImageList object item.ImageIndex = 2 'Add the items item.SubItems.Add(url.ToString()) item.SubItems.Add(info.LastAccessTime.ToString()

                  D 1 Reply Last reply
                  0
                  • D Darshon

                    Hey Dean, I did what you suggested and it works very nicely and it doesn't lag at all. At least not with my Favorites folder and I have quite a few links in there. ;-) The only problem I have now is that I have only been able to read the complete url file text and there is too much garbage text to send it as a http: address. I have to find a way to extract only the url text and put that in the hidden column. Any ideas? Thanks :-) The text I get from the StreamReader is simular to this for every url file it reads, just the actual http:// text changes. "[default]baseurl=http://www.adenak.com/\[InternetShortcut\]URL=http://www.adenak.com/Modified=1067F49A2E3BC50134" Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect 'Get reference to the selected node Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath) 'Clear all the items in the listview lvwExplorer.Items.Clear() 'Check if the Directory exist or not If (dirInfo.Exists) Then 'Get reference to all the files Dim fileInfos As FileInfo() = dirInfo.GetFiles() 'Add all the files to the ListView one by one Dim info As FileInfo For Each info In fileInfos 'First check the extension, make sure it's a url file If info.Extension = ".url" Then Try 'Open the file and read it 'Convert the file path into a string for the StreamReader Dim infoPath As String = info.FullName ' Create an instance of StreamReader to read from each file. Dim sr As StreamReader = New StreamReader(infoPath) 'Read the complete url file text Dim url As String url = sr.ReadToEnd() 'Extract only the url text **This is where I need to extract the http text** Dim item As ListViewItem = New ListViewItem item = lvwExplorer.Items.Add(info.Name) ' Link the ImageList object item.ImageIndex = 2 'Add the items item.SubItems.Add(url.ToString()) item.SubItems.Add(info.LastAccessTime.ToString()

                    D Offline
                    D Offline
                    Darshon
                    wrote on last edited by
                    #9

                    Hey Dean, I got it to work! :-) Sorry but the Newbie is excited!!! lol I figured it out. I was reading the text wrong. I was reading the whole thing in one shot instead of reading it line by line and the 4th line I had to read it in two shots. This is the reading code I did and it all works just fine now. For anyone (Newbies) that need to know how to do this here's the extra code to finish it up. Change everything between the "Dim url As String" and the beginning of the listview code to this below. 'Read the url file and get the url text Dim c(3) As Char Dim url As String url = sr.ReadLine() url = sr.ReadLine() url = sr.ReadLine() url = sr.Read(c, 0, c.Length) url = sr.ReadLine() Thanks again for all of your help Dean. :-)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups