listbox

How to set multiple selected items on a WinForms ListBox

断了今生、忘了曾经 提交于 2019-12-02 00:30:05
I have a System.Windows.Forms.ListBox in multiple selection mode and a set of items I'd like to be selected. How do I do that? [Test] public void SetListBox() { var listBox = new ListBox(); var items = new List<string>{"one", "two", "three", "four"}; listBox.SelectionMode = SelectionMode.MultiSimple; listBox.Items.AddRange(items.ToArray()); var selectedItems = new List<string> {"two", "four"}; // ??? Assert.AreEqual(selectedItems, listBox.SelectedItems); } Do this: selectedItems.Select(sd => listBox.Items.IndexOf(sd)).Where(i => i >= 0).ToList().ForEach(i => listBox.SetSelected(i, true)); For:

Have a databound WPF Listbox generate subclassed ListboxItems

大兔子大兔子 提交于 2019-12-02 00:04:55
I would like to have my WPF Listbox, which is databound, generate subclassed ListboxItems instead of the regular ListboxItems. In this case, a DataTemplate is not sufficient because I need some custom properties for the subclassed ListBoxItems. Is there a way to have the ListBox generated mySubClassedListBoxItem items for the bound data? Thanks, Bart You need to create your own subclass of ListBox so you can override the method which creates the container, e.g. public class MyListBox : ListBox { public MyListBox() { // Should get the default style & template since styles are not inherited

How to insert a check box inside a list box in C#?

痴心易碎 提交于 2019-12-01 23:58:07
I want a code to insert a checkbox inside a listbox in c sharp. on selecting the checkbox all the items in listbox must get selected. You can use a CheckListBox to display a list with a check box next to each item. But to make a single checkbox that selects everything in a list, it must be outside the list box (above or below or beside it). Then you can use code like: public void SelectAllCheckBox_CheckedChanged(object s, EventArgs e) { foreach (var item in ListBox1.Items) { item.Selected = SelectAllCheckBox.Checked; } } There is no control that has a single check box inside a list: eg this is

ListBox and ListView Highlighting .NET 4.0

南楼画角 提交于 2019-12-01 23:52:50
问题 With .NET 4.0 it appears highlighting of ListBox and ListView has changed Below is code I have used for years in several places on .NET 3.5 and highlight when not focused has stopped working on 4.0 and 4.5 <ListBox.ItemContainerStyle> <Style> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/> <!-- Background of selected item when focussed --> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/> <!-- Background of

Incorrect selection of items in an FMX TListbox (Grid Metropolis UI)

末鹿安然 提交于 2019-12-01 23:01:01
I have met an issue of unproper selection of items in TListBox in my application with a HorzScrollBox in the form. The form has two (or more) TListBox on it. They are placed away from each other so that their absolute left coordinates difference is more than the width of the current device screen width. The error appears in the following sequence of user actions. An item is selected from the left TListBox The HorzScrollBox is scrolled to the right and the second TListBox becomes visible to user and the left one - invisible. The HorzScrollBox is scrolled back to the left. An new item is

WPF TwoWay Binding of ListBox using DataTemplate [duplicate]

南笙酒味 提交于 2019-12-01 22:41:12
Possible Duplicate: How to make ListBox editable when bound to a List<string>? I'm trying to set a two-binding between a List named "ListStr" object and a ListBox WPF control. Besides I want the items to be editable, so I added a DataTemplate with TextBoxes expecting that it would modify the ListStr items straight away via TextBoxes. But when I'm attempting to edit one of them, it doesn't work... Any Idea ? PS: I've tried to add the Mode=TwoWay parameter, but it's still not working Here is the XAML : <ListBox ItemsSource="{Binding Path=ListStr}" Style="{DynamicResource ResourceKey

ListBox Shift-Click Multi-Select Anchor is not being set properly

China☆狼群 提交于 2019-12-01 22:06:38
问题 I’m at my wit’s end trying to figure this out. I'm experienced in WPF, but I've never seen anything like this. I have a ListBox that contains selectable ListBoxItems. Items in the list can be selected by mouse click or by using the up/down arrows. I’m using SelectionMode.Extended, so my list supports multiple selections. The problem: Clicking on an item in the list, then Shift-Clicking on another item selects the correct range of items like you would expect. Unfortunately, using the up/down

filter a query based on multiple list boxes in a form

北城以北 提交于 2019-12-01 21:51:52
I have an Access database with two tables: "contacts" and "country" These contain a number of fields in each. I have a query, "Filter", that brings these two tables together. I want to create a form with as many list boxes as there are fields in the query. A user can open the form and select multiple data from each list box - the row sources are tied back to the two tables above. Then on the click of a button the query would be displayed and filters would be applied dependent on the users selections in the list boxes. If nothing is selected then the query is displayed without filters.

ListBox and ListView Highlighting .NET 4.0

狂风中的少年 提交于 2019-12-01 21:51:37
With .NET 4.0 it appears highlighting of ListBox and ListView has changed Below is code I have used for years in several places on .NET 3.5 and highlight when not focused has stopped working on 4.0 and 4.5 <ListBox.ItemContainerStyle> <Style> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/> <!-- Background of selected item when focussed --> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/> <!-- Background of selected item when not focussed --> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"

Reset listbox selection in VBA

﹥>﹥吖頭↗ 提交于 2019-12-01 21:44:54
I'm trying to 'reset' a listbox in Excel VBA when a form closes. Currently when I use the userform1.hide function the form disappears but when I open it up again using the .show function it still has the previous selections in it. As someone who is relatively new to this can anyone help? The code for the listboxes is as follows: Sub CommandButton1_Click() 'Filter by Country Dim item As Long, dict As Object Dim wsData As Worksheet Set wsData = Sheets("TPID") Set dict = CreateObject("Scripting.Dictionary") With ListBox1 For item = 0 To .ListCount - 1 If .Selected(item) Then dict(.List(item)) =