listbox

ASP.NET MVC ListBox does not show the selected list items

回眸只為那壹抹淺笑 提交于 2019-12-02 04:14:43
I am in a big trouble. I read 4 stackoverflow question and one blogpost. I have tried 5 different approach to view the selected items in a multiple selectlist. I have no success. The multiple selectlist is generated, but it does not select the items. I have no more idea. Model : public class EditableModel { public IList<Company> SelectedCompanies { get; set; } public IList<SelectListItem> SelectListCompanies { get; set; } } Controller : public ActionResult Edit(int id) { var service = _serviceDAL.GetEditableModel(id); if (service!= null) { service.SelectListCompanies = GetSelectListCompanies

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

我们两清 提交于 2019-12-02 04:03:46
问题 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. 回答1: 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

Items collection must be empty before using ItemsSource

半世苍凉 提交于 2019-12-02 03:56:40
If I put a DataTrigger in a simple Listbox I get this runtime exception: Items collection must be empty before using ItemsSource My listbox without datatrigger (no exception): <ListBox ItemsSource="{Binding EdgedBoards}" SelectedItem="{Binding SelEdgedBoard, Mode=TwoWay}" DisplayMemberPath="Name"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </Style> </ListBox.ItemContainerStyle> </ListBox> My ListBox with

How to set multiple selected items on a WinForms ListBox

时光毁灭记忆、已成空白 提交于 2019-12-02 03:51:17
问题 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); } 回答1: Do this: selectedItems.Select

Set Interaction.Triggers to ListBoxItem

我与影子孤独终老i 提交于 2019-12-02 03:46:29
I have set Interaction.Triggers to ListBox and perform respective TargetedTriggerAction when 'SelectionChanged' event occurs, like below. <ListBox x:Name="WorksheetListBox" ItemsSource="{Binding WorkSheetCollection}" ItemTemplate="{StaticResource workSheetTemplate}"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <action:WorksheetListBoxAction /> </i:EventTrigger> </i:Interaction.Triggers> </ListBox> But my requirement is I need to set Interaction.Triggers to ListBoxItem's 'PreviewMouseDown' event(Note: ListBox populated via ItemsSource) You can try something like this:

How to bind to a source inside a ListBox different from the ItemsSource already specified

一曲冷凌霜 提交于 2019-12-02 03:36:21
I have a ListBox inside a HubSection, whose Items are bound to a class "players" added to my DefaulViewModel via code behind. First I simply put a TextBox bound to the property "PlayerName" of my class "players". Now I would like to add a ComboBox with some items that are NOT part of the class players. Is it possible ? I thought that definind an ItemsSource in the ComboBox would sort of override the ItemsSource of the ListBox, but nothing displays. The DataContext of the whole page is defined like so: DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" Then the

How to get the ListBoxItem for an item in ListBox on “bind-time”

南笙酒味 提交于 2019-12-02 01:49:15
问题 I have a ListBox with Foo objects, and based on some events I disable/enable the ListBoxItems in the ListBox. Using the ListBox.Items property I find Foo objects, and from what I've understood I need to use the following function to get the ListBoxItem container for the Foo. Correct? foreach (var item in Items) { var lbi = ItemContainerGenerator.ContainerFromItem(foo) as ListBoxItem; // do something } Actually I have a custom control FilteringListBox which inherit ListBox and adds an extra

(c# + windows forms) Adding items to listBox in different class

☆樱花仙子☆ 提交于 2019-12-02 01:32:06
I have two classes(forms), and I would like an item from class2 to be added to listBox in class1 when I click "Accept" button. I tried with the following code, but nothing changes in the listBox: private void button1_Click(object sender, EventArgs e) { CarRental i = new CarRental(); string id = idRental.Text.ToString(); i.listBox1.Items.Add(id); i.listBox1.Update(); this.Close(); } Where did I make the mistake? Declare RentalId property on Form2 . And at CarRental form (your first form) do following: using(Form2 form2 = new Form2()) { if (fomr2.ShowDialog() != DialogResult.OK) return; listBox

WPF: Listbox, centering selected item

为君一笑 提交于 2019-12-02 01:27:28
问题 Is it possible to always keep selected item in the middle of a listbox? If the user selects an item, I want to scroll so that the newly selected item is in the middle. I guess it want be possible for the 'edge cases' (the first and last few items), but that's ok. 回答1: David Anson posted some articles on his blog that might help you here: Part 1 and Part 2. He gives an extension method that centers an item in an List Box. You might be able to build on that. 回答2: It is possible with couple of

How to get the ListBoxItem for an item in ListBox on “bind-time”

喜你入骨 提交于 2019-12-02 01:19:20
I have a ListBox with Foo objects, and based on some events I disable/enable the ListBoxItems in the ListBox. Using the ListBox.Items property I find Foo objects, and from what I've understood I need to use the following function to get the ListBoxItem container for the Foo. Correct? foreach (var item in Items) { var lbi = ItemContainerGenerator.ContainerFromItem(foo) as ListBoxItem; // do something } Actually I have a custom control FilteringListBox which inherit ListBox and adds an extra property to it. The above code is in the code behind of the custom control and works just fine when the