0

请一些人告诉我如何从列表框控件中删除当前的 SelectedIndex 项。

这是我的代码:.................................................. ..................................................... ..................................................... ...

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        listBox1.Items.Add("www.google.com");
        listBox1.Items.Add("www.facebook.com");
        listBox1.Items.Add("www.yahoo.com");
        listBox1.SelectedIndex = 0;
        listBox1.DataSource = listBox1.Items;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        var num = listBox1.Items.Count;
        string str = Convert.ToString(num);
        textBox1.Text = str;
        for (int i = 0; i < num; )
        {
            webBrowser1.Navigate(listBox1.SelectedItem.ToString());
            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
                if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
                {
                    //what do i do to remove current SelectedIndex item from Listbox control.
                }
            }
        }
    }

}
4

1 回答 1

2

您可以使用RemoveAt直接从Items集合中删除它:

listBox1.Items.RemoveAt(listBox1.SelectedIndex);

或者,您可以删除SelectedItem

listBox1.items.Remove(listBox1.SelectedItem);
于 2012-08-18T04:11:26.383 回答