Note that there are some explanatory texts on larger screens.

plurals
  1. PONavigating to selected ListViewItem on doubleclick
    text
    copied!<p>I'm making a simple browser in Visual Studio.<br> To be able to save and delete bookmarks, I'm using these codes:</p> <p>When the frmFavorites is opened, it'll read an xml-file named Favorites.xml</p> <pre><code>private void frmFavorites_Load(object sender, EventArgs e) { System.Xml.XmlDocument loadDoc = new System.Xml.XmlDocument(); loadDoc.Load(Application.StartupPath + "\\Favorites.xml"); foreach (System.Xml.XmlNode favNode in loadDoc.SelectNodes("/Favorites/Item")) { listViewFavs.Items.Add(favNode.Attributes["url"].InnerText); } } </code></pre> <p>When the form is closed again, it'll overwrite the xml-file and save all remaining items in the xml-file</p> <pre><code>private void frmFavorites_FormClosing(object sender, FormClosingEventArgs e) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Application.StartupPath + "\\Favorites.xml", null); writer.WriteStartElement("Favorites"); for (int i = 0 ; i &lt; listViewFavs.Items.Count ; i++) { writer.WriteStartElement("Item"); writer.WriteAttributeString("url", listViewFavs.Items[i].Text); writer.WriteEndElement(); } writer.WriteEndElement(); writer.Close(); } </code></pre> <p>To add and delete a bookmark, I'm using this code:</p> <pre><code>private void btnAddFav_Click(object sender, EventArgs e) { ListViewItem item = new ListViewItem(txtURL.Text); listViewFavs.Items.Add(txtURL.Text); } private void btnDelFav_Click(object sender, EventArgs e) { try { listViewFavs.Items.RemoveAt(listViewFavs.SelectedIndices[0]); } catch { MessageBox.Show("Je moet een item selecteren", "Geen item geselecteerd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } </code></pre> <hr> <p>Now, my problem:<br> I'd like to give my users the ability to double click on an item so they can navigate to their saved fav. At least, that's what SHOULD happen.<br> For so far, I've tried some codes and ended up with this:</p> <pre><code>private void listViewFavs_DoubleClick(object sender, EventArgs e) { try { FrmMain Main = new FrmMain(); Main.navigate(listViewFavs.SelectedItems[0].Text); } catch { MessageBox.Show("Je moet een item selecteren", "Geen item geselecteerd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } </code></pre> <p>frmMain is my browser and navigate is a public method that I use to check the URL's and to navigate.</p> <p>To navigate, I use this code:</p> <pre><code>public void navigate(String URL) { if (String.IsNullOrEmpty(URL) || URL.Equals("about:blank")) { GetActiveBrowser().DocumentText = Properties.Resources.FirstTime; // this is a HTML-doc you also see when you open the browser for the 1st time txtURL.Text = "about:blank"; return; } else if (!URL.StartsWith("http://") &amp;&amp; !URL.StartsWith("https://") &amp;&amp; !URL.StartsWith("file://") &amp;&amp; !URL.StartsWith("ftp://")) URL = "http://" + URL; try { GetActiveTab().Text = "... Loading ..."; this.Icon = Properties.Resources.loading1; GetActiveBrowser().Navigate(new Uri(URL)); } catch (System.UriFormatException) { MessageBox.Show("'" + URL + "' is geen geldige URL", "Ongeldige URL", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // go to URL </code></pre> <p>As you can see, I use a GetActiveTab() and GetActiveBrowser:</p> <pre><code>private WebBrowser GetActiveBrowser() { return (WebBrowser)tabs.SelectedTab.Controls[0]; } private TabPage GetActiveTab() { return tabs.SelectedTab; } </code></pre> <p>What actually happens:<br> I double-click on the item<br> Nothing happens -.- No navigation, no error, no nothing</p> <p>Does anyone have an idea to fix this problem?<br> I appreciate any help given.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload