listbox

How to get selected items from listbox has checkboxes in WPF?

懵懂的女人 提交于 2019-12-30 06:46:28
问题 This is the ListBox code: <ListBox x:Name="courseslistview" ItemsSource="{Binding .}" FontSize="18.667" FontFamily="Trebuchet MS" LayoutUpdated="courseslistview_LayoutUpdated"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding .}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> How can I use C# to get all the checked checkboxes in the above ListBox? 回答1: It would probably be best to bind the CheckBox to the IsSelected property of the ListBoxItem , like so: <DataTemplate>

WPF Listbox remove selection by clicking on a blank spot

折月煮酒 提交于 2019-12-30 05:23:07
问题 I have a wpf listbox with a custom item template which contains a rectangle. The each item in the listbox can be selected (only one at a time). I want to add a behavior in which when a user clicks on a place which isn't the item (for instance, a blank spot on the listbox , which is not an item), the selected item will become deselected. Any ideas? Thanks. For example with a simple listbox: item 1 item 2 The behavior that I'm looking for is when the user clicks on pixel 500 (which is a part of

Multi Select List Box

安稳与你 提交于 2019-12-30 05:20:06
问题 I have a list box on a form and it works fine for what I want to do. I am wanting to edit items on the form, this means populating the listbox and then selecting the relevant items. My listbox contains a list of item sizes, i want to select the sizes which belong to the item being edited. PLease can someone give me some pointers. I tried me.lstItemSizes.SetSelected(i,true) but this only works for a single item. Any help wil be much appreciated. My Code: Private Sub SelectItemSizes(ByVal

Right Click to select items in a ListBox

冷暖自知 提交于 2019-12-30 03:43:06
问题 I'm trying to make a list of items that you can do several actions with by right-clicking and having a context menu come up. I've completed that, no problem whatsoever. But I'd like to have it so that when you right click on a item, instead of leaving the current item selected, to select the item the mouse is over. I've researched this and other related questions, and I've tried to use indexFromPoint (which I found through my research) but whenever I right click on a item, it always just

Binding Dictionary<T> to a WPF ListBox

霸气de小男生 提交于 2019-12-29 20:02:18
问题 Given a dictionary of <string, Drink> , how would you bind the dictionary.Values to a WPF ListBox, so that the items use the .Name property? struct Drink { public string Name { get; private set; } public int Popularity { get; private set; } public Drink ( string name, int popularity ) : this ( ) { this.Name = name; this.Popularity = popularity; } } 回答1: Setting the ItemsSource on an items control creates a binding to the enumerator for the source object. The enumerator of a Dictionary<T1, T2>

Binding Dictionary<T> to a WPF ListBox

瘦欲@ 提交于 2019-12-29 20:00:13
问题 Given a dictionary of <string, Drink> , how would you bind the dictionary.Values to a WPF ListBox, so that the items use the .Name property? struct Drink { public string Name { get; private set; } public int Popularity { get; private set; } public Drink ( string name, int popularity ) : this ( ) { this.Name = name; this.Popularity = popularity; } } 回答1: Setting the ItemsSource on an items control creates a binding to the enumerator for the source object. The enumerator of a Dictionary<T1, T2>

Deselection on a WPF listbox with extended selection mode

家住魔仙堡 提交于 2019-12-29 08:44:47
问题 I have a simple listbox with extended selection mode. Selection works almost perfectly fine like it works in explorer. But deselection doesn't really work all that well. What I want is that when I click on something outside the range of elements in the listbox I want all elements to be deselected. I doesn't seem to behave that way by default and I did a dirty hack involving selectionchanged and mouseup to hack it up. But there has to be a better way. Any ideas? 回答1: It isn't that dirty to add

.NET 3.5 Listbox Selected Values (Winforms)

南楼画角 提交于 2019-12-29 07:16:13
问题 I am BATTLING to get the selected values (please note VALUES not TEXT) from a Winforms Listbox that has multi-select enabled and has been bound to a database table getting the Name (as DisplayMember) and ID (as ValueMember) - I need the ID of the selected items. The listbox control has properties for SelectedValue to get one of the selected items values, but not for all selected items values. The SelectedItems property returns a Listbox.SelectedObjectCollection from which I cannot seem to

How to fit Tkinter listbox to contents

﹥>﹥吖頭↗ 提交于 2019-12-29 07:05:32
问题 I'm adding strings to a listbox using the code below. When I run the code and the window opens, the longer strings get clipped as the window is not large enough (see screenshot). I have tried making the window resizeable and adding scroll bars but I was wondering if there was a way to automatically size it to fit the content. master = tk.Tk() listbox = tk.Listbox(master, selectmode=tk.SINGLE) games = ["Garry's Mod", "Mount and Blade: Warband", "Tekkit"] for game in sorted(games): listbox

adding a ListBoxItem in a ListBox in C#?

。_饼干妹妹 提交于 2019-12-29 05:47:10
问题 I know that: String test = "test"; ListBox.Items.Add(test); or String test = "test"; int index = 1; ListBox.Items.Insert(index, String); adds the String in a ListBox, but I want to insert ListBoxItem, how to? previously I learn that var contentToString = (String)ListBoxItem.Content; simply converts ListBoxItem to String, but I couldn't do the opposite to convert String to ListBoxItem 回答1: Try this: ListBoxItem itm = new ListBoxItem(); itm.Content = "some text"; listbox.Items.Add(itm); listbox