listbox

How do I get the exact scroll position in an Listbox?

元气小坏坏 提交于 2019-12-19 08:56:05
问题 I would like to be able to load more data into a listbox when I reach the begining or the end of the listbox. My listbox shows items that are time related therefor when I reach the top and pull down I would like to see some text like "Scroll down more to retrieve more items" and if you do so it then triggers a data download for items that occur earlier. Same thing for the bottom item if you scoll down far enough (beneath the last item it triggers a data download for items later than listed).

Items on ListBox show up as a class name

狂风中的少年 提交于 2019-12-19 08:07:43
问题 The problem is as follows: I connected the ListBox with a list of elements of some custom class ( List<Person> persons = new List<Person>() ) using DataSource property. Of course ValueMember and DisplayMember are both assigned to appropriate properties of this class. When I first load data, everything looks ok. However, when I click on some item (i.e. 7th position, counting from 1) and then rebuild the list AND the number of elements is LESS than 7, as a result I can't see the proper texts on

Fill WPF listbox with string array

十年热恋 提交于 2019-12-19 07:54:44
问题 Instead of adding each item one by one to the ListBox destinationList from the string array m_List like this: foreach (object name in m_List) { destinationList.Items.Add((string)name); } Is there any better way I can do it? I don't want to bind the data to the destinationList since I want to delete some entries from the ListBox later on. 回答1: HTH: string[] list = new string[] { "1", "2", "3" }; ObservableCollection<string> oList; oList = new System.Collections.ObjectModel.ObservableCollection

How to remove multiple selected items in ListBox?

心已入冬 提交于 2019-12-19 06:56:21
问题 My windows form contains two listboxes. Listbox1 contains some items in it and listbox2 is empty. When I press a button on the form, then multiple selected items from listbox1 should be removed from Listbox1 and copied to Listbox2. I tried with foreach loop on listbox1.SelectedItems but it removes only 1 item from list. Anyone has solution or code for this? 回答1: You could do all in a single loop. You should use a simple for and loop backwards on SelectedIndices: private void button1_Click

How to remove multiple selected items in ListBox?

喜欢而已 提交于 2019-12-19 06:55:11
问题 My windows form contains two listboxes. Listbox1 contains some items in it and listbox2 is empty. When I press a button on the form, then multiple selected items from listbox1 should be removed from Listbox1 and copied to Listbox2. I tried with foreach loop on listbox1.SelectedItems but it removes only 1 item from list. Anyone has solution or code for this? 回答1: You could do all in a single loop. You should use a simple for and loop backwards on SelectedIndices: private void button1_Click

WPF ListBox - Getting UIElement instead of of SelectedItem

血红的双手。 提交于 2019-12-19 05:13:17
问题 I created a ListBox that has a DataTemplate as Itemtemplate . However, is there an easy way to access the generated UIElement instead of the SelectedItem in codebehind? When I access SelectedItem , I just get the selected object from my ItemsSource collection. Is there a way to access the UIElement (ie. the element generated from the DataTemplate together with the bound object)? 回答1: You are looking for the ItemContainerGenerator property. Each ItemsSource has an ItemContainerGenerator

How can I realize SelectionChanged in MVVM ListBox Silverlight

主宰稳场 提交于 2019-12-19 03:14:35
问题 The ListBox control does not implement a Command property. I have to attach some functionality to the SelectionChanged event. Somebody knows how can I do it? Please help me 回答1: I prefer using a binding to the SelectedItem and implementing any functionality in the setting of the binding property. <ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" /> ... public class ViewModel { public IEnumerable<Item> Items { get; set; } private Item selectedItem; public Item

Can't convert ListBox.ObjectCollection to a (typed) array

房东的猫 提交于 2019-12-18 23:38:22
问题 I want to convert the items to a String array or the type that I used to fill the ListBox.DataSource. The type has overridden ToString() but I can't seems to get it converted, not even to String[]. String[] a = (String[])ListBox1.Items; Contacts[] b = (Contacts[])ListBox1.Items; 回答1: string[] a = ListBox1.Items.Cast<string>().ToArray(); Of course, if all you plan to do with a is iterate over it, you don't have to call ToArray(). You can directly use the IEnumerable<string> returned from Cast

Value does not fall within the expected range

被刻印的时光 ゝ 提交于 2019-12-18 21:56:32
问题 I am using the following code to update a listbox, this recieving a list from a Web service: client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted); client.userKeywordsAsync(); Using: void client_userKeywordsCompleted(object sender, userKeywordsCompletedEventArgs e) { string result = System.Convert.ToString(e.Result); for (int i = 0; i < e.Result.Count; i++) { ListBoxItem lbitem = new ListBoxItem(); lbitem.Name = "lb_" + i; lbitem

Value does not fall within the expected range

流过昼夜 提交于 2019-12-18 21:54:23
问题 I am using the following code to update a listbox, this recieving a list from a Web service: client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted); client.userKeywordsAsync(); Using: void client_userKeywordsCompleted(object sender, userKeywordsCompletedEventArgs e) { string result = System.Convert.ToString(e.Result); for (int i = 0; i < e.Result.Count; i++) { ListBoxItem lbitem = new ListBoxItem(); lbitem.Name = "lb_" + i; lbitem