Might be a stupid question but...
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
-
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
-
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
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
-
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
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()
-
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()
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. :-)