In my program i took a listbox, in this listbox I added number of items.
Now I want to know how to get number of listbox items & show number of items in a textbox. when number of items is not fixed.
Let's say your listbox is called ListBox1 and textbox is TextBox1. Then the code you need is
TextBox1.Text = ListBox1.Items.Count.ToString();
Of course knowing your platform (WinForms, WebForms, Html etc.) would help a lot for a more accurate answer.
I would like to present an answer for the people who uses WPF.
<ListBox ItemsSource="{Binding Path=Parts}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Label Content="{Binding CurrentPart, Mode=OneWay}" />
<Label Content="{Binding Path=Parts.Count}"
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.