listbox

Getting Selected Items From WinForm ListBox?

别等时光非礼了梦想. 提交于 2020-01-23 09:07:25
问题 I have a ListBox in a WinForm with multiselect enabled. The selected items appear to be stored in an object, how to I get their values? 回答1: Easy, depending on what type you stored: foreach (MyItemType item in listBox1.SelectedItems) { ... } Because this is an older, non-generic collection it is better not to use var to declare the item variable. That would only get you a reference of type object . You can also use other properties like: if (listBox1.SelectedItems.Count > 0) ... 回答2: Just use

Are drop down select fields vulnerable to any sort of injection

纵饮孤独 提交于 2020-01-23 03:09:04
问题 I have read here the mantra "never trust user input" and it makes sense. I can understand that any field that is typed in by the user is suspect. However, what about drop down select fields? Can they be used for any type of injection? I have sanitized all the fields that allow a user to type in, and also used mysqli prepared statements for insertion into the database. However, there are three drop-downs in my form and was wondering if I need to do anything about them? 回答1: Every single

Populate WPF listbox based on selection of another listbox

若如初见. 提交于 2020-01-22 02:37:12
问题 I have a listbox that is bound to an observablecollection. The observable collection contains a list of objects, each with it's own observablecollection. What i want is to click an item in the first listbox and have it's list of things displayed in the second listbox. Can I do this in pure WPF? 回答1: Just bind the ItemsSource of the second listbox to the SelectedItem of the first list box. Edit: here is some code. public partial class MainWindow : Window { public MainWindow() { TestItems = new

Items in ObservableCollection<string> do not update when bound to a WPF ListBox

最后都变了- 提交于 2020-01-20 08:50:07
问题 I should like to manipulate an ObservableCollection of string s by binding it to the ItemsSource property of a ListBox and setting the item template to a TextBox . My problem is that the items in the ObservableCollection do not get updated when I edit them in the TextBox items that the ListBox contains. What am I doing wrong? The XAML of the minimum working example is <Window x:Class="ListBoxUpdate.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:/

How do add image to System.Windows.Forms.ListBox?

妖精的绣舞 提交于 2020-01-19 17:01:45
问题 I'm developing chatting program using C# and I manage nickname list using ListBox. But, client have nickname, and state (online, away) So, in order to manage the state, I want to add image (online - green circle, away - red circle) to ListBox (it is my idea) How can add image to ListBox? Please help me. Thanks. 回答1: You can't do that easily in the ListBox. And drawing them using Graphics is not easy at all. I suggest using a DataGridView o ListView control instead. Result: DataGridView :

How do add image to System.Windows.Forms.ListBox?

Deadly 提交于 2020-01-19 16:59:41
问题 I'm developing chatting program using C# and I manage nickname list using ListBox. But, client have nickname, and state (online, away) So, in order to manage the state, I want to add image (online - green circle, away - red circle) to ListBox (it is my idea) How can add image to ListBox? Please help me. Thanks. 回答1: You can't do that easily in the ListBox. And drawing them using Graphics is not easy at all. I suggest using a DataGridView o ListView control instead. Result: DataGridView :

listBox selectedIndex is always 0 unless I make the thread wait

情到浓时终转凉″ 提交于 2020-01-17 06:22:34
问题 I have a listBox populated manually. When a user selects an item I use the value of the selected index to recreate the list with new data. However, it always seems to return 0 unless I put a breakpoint in. With the breakpoint it works perfectly. I looked at the question: WPF ListBox SelectionChanged event and the suggestion to make the thread sleep for 70ms works most of the time. 200ms works even more reliably!! I am guessing this is a threading issue but I don't know how to make the event

listBox selectedIndex is always 0 unless I make the thread wait

扶醉桌前 提交于 2020-01-17 06:22:25
问题 I have a listBox populated manually. When a user selects an item I use the value of the selected index to recreate the list with new data. However, it always seems to return 0 unless I put a breakpoint in. With the breakpoint it works perfectly. I looked at the question: WPF ListBox SelectionChanged event and the suggestion to make the thread sleep for 70ms works most of the time. 200ms works even more reliably!! I am guessing this is a threading issue but I don't know how to make the event

Saving from a list box to a .csv file in c# Win Form

妖精的绣舞 提交于 2020-01-17 03:36:25
问题 I have been looking around for hours on how to do this, I think the best idea is to come up with a for each loop and then pass that through into the Stream Writer. I've tried multiple different ways, and I think maybe I'm just not good enough to see my error, if anyone would be able to help that's be great. Currently the file gets created and the only output I get for it is "System.Windows.Forms.ListBox+ObjectCollection" on the first line, which suggests to me that I'm not passing the values

WPF binding List<Dictionary<string,string>> to a ListBox

落爺英雄遲暮 提交于 2020-01-17 01:39:49
问题 var list = new List<Dictionary<string, string>>{ new Dictionary<string,string>{ {"id","1"}, {"name","foo"}, }, new Dictionary<string,string>{ {"id","2"}, {"name","bar"}, } }; I want to bind this list to a listbox. It's quite simple: listBox.ItemsSource=list; but the problem is: I can't control what is displayed in the listbox. What I want is to display is dict["name"]. I tried: listbox.DisplayMemberPath="name" Sadly it doesn't work. 回答1: Your code tries to display a property called name on