Click here to Skip to main content
15,851,242 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying so that a label always shows the number of items in the listbox, all i got for this is remove button that removes the selected item and one that adds an item. how do i put these all together so that the label always shows the listbox's item count?
Posted

private void btn_Add_Click(object sender, EventArgs e)
        {
        //Adding /////
     Label1.text = Convert.tostring(ListBox1.Items.Count);

     }


private void btn_Remove_Click(object sender, EventArgs e)
        {
        //Removing /////
     Label1.text = Convert.tostring(ListBox1.Items.Count);

     }
 
Share this answer
 
Comments
[no name] 11-May-11 21:00pm    
When i click the button to add a item. the buttons number stays the same and it isn't the number 1 of how meny items i had added to the listbox. so when i click it again, the number goes to 2, the listboxs items in there is achilly 1
On the Add Button event

Label1.text=" ";
after Adding / Removing

Label1.text = Convert.tostring(ListBox1.Items.Count);
 
Share this answer
 
Comments
[no name] 11-May-11 6:58am    
my problem now is that the number is always 1 less then the label
Mahendra.p25 11-May-11 7:02am    
not clear plz elaborate
[no name] 11-May-11 7:18am    
When i click the button
to add a item. the buttons number stays the same and it isn't the number 1 of how meny items i had added to the listbox. so when i click it again, the number goes to 2, the listboxs items in there is achilly 1
Kim Togo 11-May-11 7:03am    
Good answer. But try to use Label1.Text = string.Empty and not Label1.Text = ""
It is much easier to read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900