i currently trying to view all the files and folder selected by the user in a listbox. At the Moment i am able to list what the user have chosen using the openfiledialogue HOWEVER i am now facing prob when i try to remove it form the listbox. i trying to allow the user to click on the checkbox beside the file and press the remove button to remove it
this is my code for remove button
private void button2_Click(object sender, EventArgs e)
{
for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
{
listView1.Items.Remove(listView1.SelectedItems[i]);
}
}
this is the add file to listbox for reference jsut in case
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
// Display open file dialog
openfiledialog.InitialDirectory = "C:\\";
//openfiledialog.Multiselect = true;
openfiledialog.Title = "Lock File";
openfiledialog.Filter = "All Files | *.*";
openfiledialog.ShowDialog();
if (openfiledialog.FileName != "")
{
//move through FileInfo array and store in new array of fi
listView1.Items.Clear();
foreach (string file in openfiledialog.FileNames)
{
listView1.Items.Add(file);
}
}
}
and i pressed the remove button nothing happen and i saw some answer on google on the using of selectionmode but when i used that, my listbox does not have the property of selectionmode and have red lines underlined
Instead of using
listView1.SelectedItemsuselistView1.CheckedItemsand change yourbutton2_clickto: