listbox

How do i split a String into multiple values?

大憨熊 提交于 2019-12-17 07:41:10
问题 How do you split a string? Lets say i have a string "dog, cat, mouse,bird" My actual goal is to insert each of those animals into a listBox, so they would become items in a list box. but i think i get the idea on how to insert those items if i know how to split the string. or does anyone know a better way to do this? im using asp c# 回答1: string[] tokens = text.Split(','); for (int i = 0; i < tokens.Length; i++) { yourListBox.Add(new ListItem(token[i], token[i])); } 回答2: Have you tried String

Selecting a Textbox Item in a Listbox does not change the selected item of the listbox

假如想象 提交于 2019-12-17 04:59:09
问题 I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox? 回答1: We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such: <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <EventSetter

Selecting a Textbox Item in a Listbox does not change the selected item of the listbox

扶醉桌前 提交于 2019-12-17 04:58:38
问题 I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox? 回答1: We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such: <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <EventSetter

Databinding to List - See changes of data source in ListBox, ComboBox

喜夏-厌秋 提交于 2019-12-17 03:24:08
问题 I want that the ListBox automatically show changes when I remove or add an object to the list which I use as its DataSource . How can I connect a List<T> to a ListBox and see changes of underlying list in ListBox immediately? 回答1: In Windows Forms , in a scenario that you want to see changes of data source in the bound list control, like ComboBox , ListBox or DataGridView (complex two-way data binding), you should use a class that implements IBindingList interface as DataSource of data

There is no ListBox.SelectionMode=“None”, is there another way to disable selection in a listbox?

梦想与她 提交于 2019-12-17 03:22:39
问题 How do I disable selection in a ListBox? 回答1: Approach 1 - ItemsControl Unless you need other aspects of the ListBox , you could use ItemsControl instead. It places items in the ItemsPanel and doesn't have the concept of selection. <ItemsControl ItemsSource="{Binding MyItems}" /> By default, ItemsControl doesn't support virtualization of its child elements. If you have a lot of items, virtualization can reduce memory usage and improve performance, in which case you could use approach 2 and

Get the value for a listbox item by index

六月ゝ 毕业季﹏ 提交于 2019-12-17 03:18:31
问题 This must be very easy but I am stuck. I have a listBox with X Items. Each Item has a text description (Which appears in the listBox) and its value(numerical). I want to be able to get the value property of an item, using the index number of the item. 回答1: It would be String MyStr = ListBox.items[5].ToString(); 回答2: Here I can't see even a single correct answer for this question (in WinForms tag) and it's strange for such frequent question. Items of a ListBox control may be DataRowView ,

How to display a dictionary which contains a list in a listBox C#

让人想犯罪 __ 提交于 2019-12-14 04:26:17
问题 I currently have a dictionary which contains a key value and a list associated with that key. I have read How to bind Dictionary to ListBox in winforms and when I try to implement that it just displays the key value. What I am trying to do is have two separate listboxs. In box 1 you select the key value, when this happens box 2 displays the list. The current code is below: var xmlDoc2 = new XmlDocument(); xmlDoc2.Load(textBox1.Text); Dictionary<string, List<string>> dict = new Dictionary

How to prevent Listbox jumps to ítem?

只愿长相守 提交于 2019-12-14 04:22:50
问题 Suppose that in a WinForms I have a Listbox with multiselect enabled, listbox contains 50 items and only the first item of the listbox is selected... ...Then if I select (using SetSelected method) the last item then the listbox will jump to bottom (together with the vertical scroll) to show me that item. I just want that the listbox stays in the position that it was, while I use SetSelected to select other items, I don't want the listbox moving up and down everytime. So how I can prevent the

Create a custom collection like BindingList that works with ListBox to create a ListChanging event

半城伤御伤魂 提交于 2019-12-14 04:00:00
问题 I have a situation where I need to know when an item is going to be added/removed/modified in the collection. I tried by inheriting BindingList in a class that will trigger these events, however the "adding" event doesn't work. The only way I found it working is by overriding EndNew() method, however I don't find a way to get which object is going to be added in this method (if someone has a solution for this, it's ok too!) . So built a totally new class which inherits from same interfaces

How to address generated ListBoxes and add Items dynamically in VBA?

青春壹個敷衍的年華 提交于 2019-12-14 03:59:59
问题 I successfully managed to generate ListBoxes dynamically. But I am now struggling with addressing and populating those generated ListBoxes. Additionally, I can't figure out how to activate the MultiSelect Property of those ListBoxes. Is that only possible with ActiveX? I first tried ActiveX - ListBoxes on userForm. Now I switched back to "normal" ListBoxes on the WorkSheet. "FS" is the name of my Worksheet which I am working on. For understanding: I am looping through the columns on worksheet