Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove items from listbox

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
US
I've tried a couple of approaches to do this. I simply have a button to remove highlighted items from a ListBox. I am using C#.NET 2003

Thanksin advance for any help you can provide!


private void btnCopyFrom_Click(object sender, System.EventArgs e)
{
// foreach (string d in this.lstPCNamesApply.SelectedItems)

foreach (short i in this.lstPCNamesApply.IndexFromPoint(0))
{
// MessageBox.Show(d);
// this.lstPCNamesApply.Items.Remove(d);

MessageBox.Show(i);
this.lstPCNamesApply.Items.RemoveAt(i);
}
}
 
Figured it out!

private void btnCopyFrom_Click(object sender, System.EventArgs e)
{
string[] iListBox = new string[this.lstPCNamesApply.SelectedItems.Count];
this.lstPCNamesApply.SelectedItems.CopyTo(iListBox, 0);

foreach (string d in iListBox)
{
MessageBox.Show(d);
this.lstPCNamesApply.Items.Remove(d);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top