listbox

How can i know if a ListBoxItem is the last item inside a Wpf's ListBox?

∥☆過路亽.° 提交于 2019-12-02 07:51:56
How can i know if a ListBoxItem is the last item of the collection (in the ItemContainerStyle or in the ItemContainer 's template) inside a Wpf's ListBox ? That question is because I need to know if an item is the last item to show it in other way. For example: suppose i want to show items separated by semi-colons but the last one: a;b;c This is easy to do in html and ccs, using ccs selector. But, how can i do this in Wpf? As it seems to be rather difficult to implement an "Index" attached property to ListBoxItem to do the job right, I believe the easier way to accomplish that would be in MVVM

Populating ListBox with List of <class> VB.NET

China☆狼群 提交于 2019-12-02 07:43:55
问题 I have a class called optionCode: Class optionCode Public description As String Public optCode As String End Class I have a query the returns a list of this optionCode class: Dim _SelectActiveOptionCodes2 = (From _OptCodes In _EntityModel.tblOptionCodes Where _OptCodes.fdStatus = "A" Select New optionCode With {.description = _OptCodes.fdDescription, .optCode = _OptCodes.fdOptionCode}).ToList() I want to use this list to populate a listbox where the description is the display field and the

Set Interaction.Triggers to ListBoxItem

笑着哭i 提交于 2019-12-02 07:40:37
问题 I have set Interaction.Triggers to ListBox and perform respective TargetedTriggerAction when 'SelectionChanged' event occurs, like below. <ListBox x:Name="WorksheetListBox" ItemsSource="{Binding WorkSheetCollection}" ItemTemplate="{StaticResource workSheetTemplate}"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <action:WorksheetListBoxAction /> </i:EventTrigger> </i:Interaction.Triggers> </ListBox> But my requirement is I need to set Interaction.Triggers to

Bind textbox list inside listbox in wpf

倖福魔咒の 提交于 2019-12-02 07:26:20
I have to make listbox with textbox in it... and it has to be dynamic. I have observable collection in code behind and I want to bind that for listbox. I want dynamic listbox and this list should have editable textbox in it. So, basically I want to bind multiplr textbox from listbox. Any help would be appreciated <ListBox HorizontalAlignment="Left" Name="ListTwo" Height="100" Margin="286.769,165.499,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Source=obs}"> <ListBox.ItemTemplate> <DataTemplate> <TextBox Name="TextBoxList"></TextBox> </DataTemplate> </ListBox.ItemTemplate> <

How to get particular property from item selected in ListBox

只谈情不闲聊 提交于 2019-12-02 07:13:32
问题 I have the following: <ListBox SelectedItem="{Binding SelectedItem}" ItemsSource="{Binding items}" DisplayMemberPath="s"/> <TextBlock Text="{Binding SelectedItem.s}"/> This is definition of SelectedItem public MemEntity SelectedItem {get; set;} MemEntity is a class containing public String s {get; get;}. Basically, I want s of the selected item to be shown in the TextBlock (same property as shown in ListBox ). This doesn't work, so what am I doing wrong? 回答1: Try this, <TextBlock ... Text="

How do I change the color of a word inside a listbox

只愿长相守 提交于 2019-12-02 06:37:34
I made a Form with a TextBox that accepts a word and searches a bunch of sentences to see if any of them contains that word .After that I have to appear those sentences and highlight the word .My plan is to make a ListBox and add the sentences inside of it. My problem is how to highlight the word (by changing the color I suppose) so it can be distinguished. Is there a preferable way? I chose ListBox so I can select the sentence I'm looking for. Edit According to @Thorsten Dittmar directions a create an owner drawn list box. public partial class Form1 : Form { private List<string> _items;

C# - Error “not all code paths return a value” with an array as out parameter

╄→尐↘猪︶ㄣ 提交于 2019-12-02 06:32:17
I currently have the below code: public int GetSeatInfoString(DisplayOptions choice, out string[] strSeatInfoStrings) { strSeatInfoStrings = null; int count = GetNumOfSeats(choice); if ((count <= 0)) return 0; strSeatInfoStrings = new string[count]; int i = 0; for (int index = 0; index <= m_totNumOfSeats - 1; index++) { if (string.IsNullOrEmpty(m_nameList[index])) strSeatInfoStrings[i++] = m_nameList[index].ToString(); } } This code produces an error of, "...GetSeatInfoString.DisplayOptions, out string[])': not all code paths return a value. Basically, what I am looking to do in the above

How do I get the index of a listboxitem in a WPF listbox instance?

不羁的心 提交于 2019-12-02 06:31:22
The listbox is databound, binding to a collection of XML nodes through xmldataprovider. Rachel I had a similar question which was answered here Basically you set the ListBox's AlternationCount to something really high, and bind to the AlternationIndex on each item <ListBox AlternationCount="100"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=(ItemsControl.AlternationIndex)}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> You can get the index of the ListBoxItem from the ItemContainerGenerator:

Get data from clicked item in ListBox

血红的双手。 提交于 2019-12-02 06:04:07
I am new to Windows Phone, I have one listbox with textblocks in it, I want to fetch all data from selected item in listbox. Here is my code snippet: .xaml file <ListBox HorizontalAlignment="Left" Name="listbox1" ItemsSource="{Binding}" Margin="9,10,0,0" SelectionChanged="listBox1_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,0,0,5"> <Image HorizontalAlignment="Left" Height="100" Margin="0,15,0,0" VerticalAlignment="Top""/> <TextBlock Text="{Binding AttractionName}" Foreground="Yellow" Margin="120,-110,0,0""/> <TextBlock Text="Price:" Foreground="White"

How to retrieve selected values for selected items in a ListBox?

不羁的心 提交于 2019-12-02 06:03:46
I'm populating a ListBox in a WinForms application, this way: listBoxUsers.DataSource = ctx.Users.ToList(); listBoxUsers.DisplayMember = "Name"; listBoxUsers.ValueMember = "Id"; how to retrieve the selected Ids when I'm setting the SelectionMode to MultiSimple I want to do a foreach loop on them, like this: foreach(var itemId in listBoxUsers.SelectedValues)//unfortunately not exist { int id = int.Parse(itemId); // . . . } Since you know the type of items, you can use such code: var selectedValues = listBox1.SelectedItems.Cast<User>().Select(x=>x.Id).ToList(); Side Note: The ListBox control