listbox

Parse XML and populate in List Box

不羁岁月 提交于 2019-12-01 01:45:58
I'm a newbie to C#. I want to develop C# List box in Windows Form. I found this link to be helpful. But the input to the List box will be an XML of the following format: <LISTBOX_ST> <item><CHK></CHK><SEL>00001</SEL><VALUE>val01</VALUE></item> <item><CHK></CHK><SEL>00002</SEL><VALUE>val02</VALUE></item> <item><CHK></CHK><SEL>00003</SEL><VALUE>val03</VALUE></item> <item><CHK></CHK><SEL>00004</SEL><VALUE>val04</VALUE></item> <item><CHK></CHK><SEL>00005</SEL><VALUE>val05</VALUE></item> </LISTBOX_ST> The XML has to be parsed and should be populated in the list box. When particular item in the list

WP7 - Animating add/remove item in a ListBox

假装没事ソ 提交于 2019-12-01 01:43:24
问题 I know you can achieve this in Silverlight 4 by playing with the ListBoxItem style's LayoutStates, i.e. BeforeUnloaded, BeforeLoaded and AfterLoaded. It doesn't seem to be working at all in WP7 although these states exist in the default style. I am currently using version 7.1. Is there any way I can get this working? Thanks, Xin 回答1: for this I used Artefact Animator, it's for Silverlight but works perfectly for WP7 also. The code shows only the addition. Whole code from the project's sample

How can I find listbox item index with item value?

谁都会走 提交于 2019-12-01 01:32:19
问题 my MessageBox.Show(listbox.Items[0].ToString()); is "abber" how can I find listbox item index 0 with "abber"? 回答1: With listbox.Items.IndexOf("abber") That is: int curIndex = listbox.Items.IndexOf("abber"); if(curIndex >= 0) { MessageBox.Show(listbox.Items[curIndex].ToString()); } 回答2: int index = listBox1.Items.IndexOf("Specify string here"); 来源: https://stackoverflow.com/questions/17611537/how-can-i-find-listbox-item-index-with-item-value

Windows.Forms.ListBox with OwnerDrawVariable bug?

邮差的信 提交于 2019-12-01 01:21:40
In a Windows.Forms.ListBox with the property DrawMode set to OwnerDrawVariable , the ListBox seems to cache the height of the items, what is good. BUT, being the item height dependent of the width, because it uses Graphics.MeasureString to do word wrap, needs to calculate the height of items if the size of the ListBox has changed. Then there's a problem. The ListBox doesn't do this by default, and I can't find a method to clear the cache, forcing the ListBox to raise the itemheight event. Any solution? I tried to get the source for the ListBox but don't find anything about that to make a

wpf Listbox giving columns a header

时间秒杀一切 提交于 2019-12-01 01:10:30
问题 I have the following markup (xaml): <ListBox Name="lbEurInsuredType" HorizontalContentAlignment="Stretch"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="0,2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="30"></ColumnDefinition><ColumnDefinition Width="2"></ColumnDefinition> <ColumnDefinition Width="30"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Title}"></TextBlock> <TextBox Text="{Binding Uw}" Grid

Keyboard focus to list box items in WPF [duplicate]

怎甘沉沦 提交于 2019-12-01 01:00:04
This question already has an answer here: WPF ListBoxItem selection problem 3 answers I am having a list box, and its item template is having one check box. Now, when I click on the check box in the listbox, it sets the checked status of the check box. If I use keyboard "Space" key, I cannot change the checkbox state. Note: Keyboard is shortcut is working once I set focus to the check box by clicking it. If you don't want the ListBox to provide selection at all, you could use a plain ItemsControl instead of a ListBox: <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate>

ListBox mouse over background color

僤鯓⒐⒋嵵緔 提交于 2019-12-01 00:32:01
The problem I have is the MouseOver trigger to color the background fails on the selected row. For any non-selected row the background turns blue on mouse over. But no blue background for the selected row. Click on a row and then the background blue goes away. I also tried the style in the ListBox.ItemContainerStyle <Window x:Class="ListBoxLastIntoView.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="0"/>

Listbox item WPF, different background color for different items

江枫思渺然 提交于 2019-12-01 00:10:41
问题 I have a WPF ListBox containing a binded list of items from a specific class that I have. Something like this: ObservableCollection<MyTable> tables = new ObservableCollection<MyTable>(); ... listTables.ItemsSource = tables; And the XAML: <ListBox HorizontalAlignment="Left" Margin="8,10,0,0" Name="listTables" Width="153" ItemsSource="{Binding tables}" SelectionChanged="listTables_SelectionChanged" Height="501" VerticalAlignment="Top"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="1">

Event handler that will be called when an item is added in a listbox

主宰稳场 提交于 2019-11-30 22:49:24
问题 Is there an event handler that will be called when an item is added in a listbox in WPF? Thanks! 回答1: The problem is that the INotifyCollectionChanged interface which contains the event handler is explicitly implemented, which means you have to first cast the ItemCollection before the event handler can be used: public MyWindow() { InitializeComponent(); ((INotifyCollectionChanged)mListBox.Items).CollectionChanged += mListBox_CollectionChanged; } private void mListBox_CollectionChanged(object

How to get multiple selected items in listbox wpf?

家住魔仙堡 提交于 2019-11-30 22:26:25
I am confused on how to retrieve multi selected values from listbox in wpf. In XAML I have the following listbox with selection mode multiple. <ListBox Height="100" HorizontalAlignment="Left" Margin="139,207,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" SelectionChanged="listBox1_SelectionChanged" SelectionMode="Multiple" /> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="319,220,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> How do I check in foreach loop now? foreach (ListItem li in listBox1.Items) { ?? // how to check li is