i want to clear one item in listbox [Resolved]

Posted by Ephibr under C# on 3/5/2011 | Points: 10 | Views : 5069 | Status : [Member] | Replies : 13
I want to clear one item in listbox how I get the index or another approach.




Responses

Posted by: Mcadeepuraj on: 3/5/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Listbox.items.removeat(index)

Deepak Kumar

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Please brief your requirement... do u need to remove only one item from the list box? or clear the list box?

Thanks
Karthik
www.f5Debug.net

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ephibr on: 3/5/2011 [Member] Starter | Points: 25

Up
0
Down
yes, only one item in atime it;s in winforms c#.

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Try this

listboxName.SelectedItems.Clear()


Thanks
Karthik
www.f5Debug.net

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ephibr on: 3/5/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks!!

I already tried it but it doesn't clear it even I saw in debug it get to this line.

string value1;
value1= this.listBox1.Items[1].ToString();
if(listBox1.Text == value1)
{

listBox1.SelectedItems.Clear();


}

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Its not clearing in the sense still the item remains in the list?

Thanks
Karthik
www.f5Debug.net

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 3/5/2011 [Member] Starter | Points: 25

Up
0
Down
This should just work fine.

You can always try hard code:)

Get all the values of list in array, remove unwanted value and bind the array again to list box. Let me know if you need code for this. I will be happy to help

Best Regards,

VG
www.TeacherJi.com

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ephibr on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
You all were very helpfull, I got it it's working.
Thanks a lot

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
Good to hear!

What is the solution you have applied?

Best Regards,

VG
www.TeacherJi.com

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
You can post the solution here so that it will be helpfiul for others as well...

Thanks
Karthik
www.f5Debug.net

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ephibr on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int selectedIndex = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(selectedIndex);
}

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Thanks Ephibr!!!

Thanks
Karthik
www.f5Debug.net

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsolvers on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
This is cool!

Best Regards,

VG
www.TeacherJi.com

Ephibr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response