listbox

WPF ListBox generate items as user scrolls

与世无争的帅哥 提交于 2019-12-10 19:06:15
问题 I am trying to use a ListBox to display a possibly infinite list of options to a user. Currently, I am simply cutting off the list at an arbitrary point, but I would like to allow the user to scroll down as far as they want. Also, I want to avoid generating non-visible items as much as possible as some computation has to be done to generate each item. I tried writing listBox.ItemsSource = enumerable expecting it to only ask the enumerable for visible items, but instead it tries to read all of

if ListBox Contains, don't add

假如想象 提交于 2019-12-10 18:19:21
问题 I've got a Method: FillListBox(); I call this method from different places.. But sometimes it happens, that things were loaded twice! Now I'm trying to do something like: if (listBox.Items[1].ToString() == "hello") { DO NOT FILL } else { FILL } THIS DONT WORKS! :( Fault: InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index And something like that: if(listBox.Items.Contains("hello")) { DONT FILL } Dont works too :( What can I do? 回答1: Try this if(ListBox.NoMatches !=

Updating listbox without losing selected item, WPF

◇◆丶佛笑我妖孽 提交于 2019-12-10 18:16:00
问题 Listbox is updated every sec and during work I need to select some of it's items and execute a command, which is impossible, because listbox is updated and loses it's selected item. ObservableCollection is the ViewModel of my list. I have some options in mind and perhaps there are better solutions: Detect new items in the list to be propagated and add new items to ObservableCollection without reinitializing ObservableCollection Detect changes in the old items and updated their fields if

Bind values from a list array to listbox

筅森魡賤 提交于 2019-12-10 18:12:33
问题 Could any body give a short example for binding a value from list array to listbox in c#.net 回答1: It depends on how your list array is. Let's start from an easy sample: List<string> listToBind = new List<string> { "AA", "BB", "CC" }; this.listBox1.DataSource = listToBind; Here we have a list of strings, that will be shown as items in the listbox. Otherwise, if your list items are more complex (e.g. custom classes) you can do in this way: Having for example, MyClass defined as follows: public

Resizing Listbox Contents according to Listbox dimensions

左心房为你撑大大i 提交于 2019-12-10 17:45:03
问题 I am attempting to resize the contents of my listbox according to the listbox itself. This is being done in WPF. Any ideas on how this might be possible? 回答1: I assume when you say "resize" you mean that you want to stretch the items in both directions. To take a default ListBox and stretch the items horizontally all you need is: <ListBox HorizontalContentAlignment="Stretch"/> The default is Left so all the ListBoxItems end up pushed to the left and sized individually based on their content.

WPF: Get a ListBoxItem as CheckBox with a Template Style to synchronize with IsSelected

前提是你 提交于 2019-12-10 17:22:00
问题 I'm making a MVVM WPF application, in this application I have a ListBox with my own Privilege Items. After ages I finally found a solution how to get selection synchronized with my ViewModel. (You also need to implement IEquatable in your item class) Problem Now i want to style the ListBoxItems as CheckBoxes, there are many solutions for this problem, but none that really fits my needs. So i came up with this solution, because I can apply this style only to the ListBoxes I need, and I don't

Group panel of WPF ListBox

浪尽此生 提交于 2019-12-10 16:26:10
问题 I have a listbox that is grouping the items with a GroupStyle. I would like add a control at the bottom of the stackpanel that holds all of the groups. This additional control needs to be part of the scrolling content so that the user would scroll to the bottom of the list to see the control. If I were using a listbox without the groups, this task would be easy by modifying the ListBox template. However, with the items grouped, the ListBox template seems to only apply on a per group basis. I

Listbox content in another application

血红的双手。 提交于 2019-12-10 16:10:05
问题 How can i read a listbox items in another application's window? I could get the window's handle but i dont know a clear way to access components within. 回答1: You can try to get something from the following project, where is shown, how to enumerate child windows, filter them for a given class name and how to get the items of a list box. I would comment it, but this would be a long story, so please take it as a temporary post ... Unit1.pas unit Unit1; interface uses Windows, Messages, SysUtils,

shift +click functionality on listbox item using WPF

我是研究僧i 提交于 2019-12-10 15:44:53
问题 I need to add functionality on List box Item where the user can select the item by clicking each item individually and can also do shift+click to select a series of items in the list. <ListBox ItemsSource="{Binding ItemFields, Mode=TwoWay}" VerticalAlignment="Stretch" HorizontalAlignment="Left" Margin="16,156,0,34" Name="fRListbox" Width="499" > <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>

Bind ListBox with multiple fields

眉间皱痕 提交于 2019-12-10 15:44:47
问题 I am using VS2010 for c#. I have some data there in a table Scores(team1,team2,battingteam,bowlingteam,score) I am using bindingSource to bind it with my listBox. The problem is that i can show only one member in DisplayMember property of listbox (e.g. team1 or team2 only). I want to do something like team1 + " vs " + team2 + ": " + battingteam +" Score: " + score how to do that? 回答1: I don't know in which data type you have your data ... but for example if you have them in DataTable returned