0
if (productListBox.SelectedIndex >= 0)
                {
                    bool canDelete = true;
                    for (int i = 0; i < bkmNameListBox.Items.Count; i++)
                    {
                        if (((string[])bkmList[i])[1] == _IgnoredBKMID)
                        {
                            canDelete = false;
                        }
                    }
                    if (canDelete)
                    {
                        if (MessageBox.Show("Deleting a product will DELETE ALL debug BKM of this particular product,\r\n Continue?", "Delete Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            DatabaseAccess.DeleteProduct(productListBox.SelectedItem.ToString());
                            LoadListBox1();
                            bkmNameListBox.Items.Clear();
                        }
                    }
                    else
                    {
                        MessageBox.Show("You cannot delete this product because one if its Debug BKM is in editing", "Access Denied");
                    }
                }

productListBox内の1つのアイテムを削除する上記のコード。複数のアイテムを削除するように変更するにはどうすればよいですか?ありがとう。

4

2 に答える 2

1

これを試して:

    private void Form1_Load(object sender, EventArgs e)
    {
        bkmNameListBox.SelectionMode = SelectionMode.MultiExtended;
    }
    private void button1_Click(object sender, EventArgs e)
    {

        while (bkmNameListBox.SelectedItems.Count > 0)
        {
            Removedatabasefiled(bkmNameListBox.SelectedItems[0]);
            bkmNameListBox.Items.Remove(bkmNameListBox.SelectedItems[0]);
        }
    }
于 2012-06-25T06:04:13.857 に答える
0
listBox1.SelectionMode = SelectionMode.MultiExtended;

コメントリンクにあるように、をループして1 SelectedIndicesつずつ削除します

for (int i = listBox1.SelectedIndices.Count-1; i >= 0; i--)
    {
     listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);

      //Delete from datasource, in case indices are the same  
      DatabaseAccess.DeleteProduct(listBox1.SelectedIndices[i]);
    }
于 2012-06-25T06:03:05.557 に答える