Jonathan Crispe

Jonathan Crispe

  • NA
  • 46
  • 48.4k

Using webbrowser, listbox...

Sep 24 2011 2:18 AM
The toolbox i'm using are: listbox, webbrowser, textbox and 3buttons(bookmark, delete. Go).

i have a problem with delete button.  At first i can delete what i bookmark, but when i bookmark again
and delete it, it's not working, the delete button becomes disable...
i want to know how to do double click the selectedindex from listbox.
Also, i want to know how to do:
When the form is closed, the current contents of the listbox will be stored in the bookmarks textfile (called bookmarks.txt). If a file error occurs, display a messagebox specifying the error.

Thank ypu for your help..

My code is this:
        private void btn_go_Click(object sender, EventArgs e)
        {
            wBrowser.Navigate(tbx_website.Text);
        }

        private void btn_bookmark_Click(object sender, EventArgs e)
        {
            //Add the url to the listbox
            LBlist.Items.Add(tbx_website.Text);
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            // The Delete button was clicked
            int i_delete = LBlist.SelectedIndex;
           
            try
            {
                // Remove the item in the List.
                LBlist.Items.RemoveAt(i_delete);

                if (LBlist.Items.Count == 0)
                {
                    btn_delete.Enabled = false;
                }
            }
            catch
            {
            }
        }

        private void listbox_DoubleClick(object sender, EventArgs e)
        {
            tbx_website.Text = LBlist.SelectedIndex.ToString();
           
        }

        private void wBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            tbx_website.Text = wBrowser.Url.ToString();
        }

        private void LBlist_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (LBlist.Items.Count == 0)
            {
                btn_delete.Enabled = false;
            }
        }



Answers (7)