listbox

Why foreach works while removing items from ListView and doesn't work from ListBox?

▼魔方 西西 提交于 2020-01-03 19:37:16
问题 I've started learning C# and I'm a bit confused about the behavior that I discovered. I try to figure out, why in one case the code is working and in another not: foreach (ListViewItem l in listView1.SelectedItems) l.Remove(); foreach (object l in listBox1.SelectedItems) listBox1.Items.Remove(l); First one works fine and there is no error, but the second one throws exception with information that the collection was changed. Could anyone explain it to me? PS. In case of ListView I was

Events for adding/removing items in a listbox c#.NET

…衆ロ難τιáo~ 提交于 2020-01-03 19:01:20
问题 I have a listbox control that has item s dynamically added to and manually removed from (due to 'remove item' button). When the number of items is changed, I would like to update other parts of the user interface - namely a caption that says 'You must choose some files.' and an item count caption. How can an event handler or effectively an event handler be added to fire when the number of items is changed - e.g. an ItemAdded or ItemRemoved or ItemsChanged Note: This is nothing to do with the

Events for adding/removing items in a listbox c#.NET

南笙酒味 提交于 2020-01-03 19:00:51
问题 I have a listbox control that has item s dynamically added to and manually removed from (due to 'remove item' button). When the number of items is changed, I would like to update other parts of the user interface - namely a caption that says 'You must choose some files.' and an item count caption. How can an event handler or effectively an event handler be added to fire when the number of items is changed - e.g. an ItemAdded or ItemRemoved or ItemsChanged Note: This is nothing to do with the

ListBox insert items in color

落爺英雄遲暮 提交于 2020-01-03 17:29:51
问题 I use ListBox for inserting text like You add Michael in your database , You delete Michael , ... listBox1.Items.Insert(0,"You add " + name + " in your database\n"); It works ok. How can i set color once black (for insert) and once red (for deletion)? I tried with this: public class MyListBoxItem { public MyListBoxItem(Color c, string m) { ItemColor = c; Message = m; } public Color ItemColor { get; set; } public string Message { get; set; } } private void listBox1_DrawItem(object sender,

ASP.Net — <select> items not being posted back after jQuery populates list

放肆的年华 提交于 2020-01-03 16:56:27
问题 I have an ASP.Net ListBox that I'm trying to populate via jQuery, using the following snippet: $("#MyList_btnAddAll").click(function(e) { e.preventDefault(); $('#MyList_lstAll option').appendTo('#MyList_lstSelected'); }); The code has two ListBoxes in fact, one a "source" and the other a "destination". As you can tell above the ListBoxes are MyList_lstAll and MyList_lstSelected. These are rendered in the browser as elements, as you'd expect. The jQuery is working great, the items are moving

Why does ListBox AlternationIndex always return 0

ぐ巨炮叔叔 提交于 2020-01-03 09:08:00
问题 Ok, I know there are a couple of other similar questions to this but I am having a real issue with getting the AlternationIndex to work on ListBox or ListView. my xaml is such: <ListBox BorderThickness="0" Name="RecentItemsListBox" HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=RecentFilesList}" AlternationCount="100"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox

Multiple WPF ListBoxes with only one item selected at a time

强颜欢笑 提交于 2020-01-03 08:41:39
问题 I am using MVVM and am displaying two listboxes on one window. I am binding from both of those listboxes simultaneously to different fields call them A and B. A and B are then both modifying C. To make this work, I want to only have one item from the two listboxes IsSelected at once, so that A does not override C when B IsSelected. How can I restrict this? 回答1: I can think of a couple of ways to do this. One way is you could bind the ListBox.SelectedIndex of your 2 ListBoxes to change

C#'s ListBox doesn't see my overrided Sort() method

一世执手 提交于 2020-01-03 03:57:09
问题 I'm trying to override Sort() method in my custom control. When my control contains ListBox and then I override Sort() method, everything works. But when I want my ListBox (1) to be extended by another ListBox (2) , that contains Sort() method, and then add that ListBox (1) to my UserControl, then it sorts too, but isn't using my Sort() method (seems like it doesn't see my Sort(), just normal Sort() from ListBox class). My ListBox (2) contains code: //... public class MyListBox: ListBox {

Change style for all ListBoxItem in a ListBox (Windows phone 8)

烂漫一生 提交于 2020-01-03 03:35:20
问题 I have a Listbox with some Listboxitem and I would like to change the style of all items. I know, it's possible to create a style in resources and bind this style to each item but maybe is there a possibility to do it so easier (without binding)? With ListBox.ItemTemplate? <ListBox SelectionChanged="ListBox_SelectionChanged"> <ListBoxItem x:Name="ItemAdress"> .... </ListBoxItem> <ListBoxItem x:Name="ItemPhone"> .... </ListBoxItem> <ListBoxItem x:Name="ItemEmail"> .... </ListBoxItem> </Listbox

Disabling “Drag Selection” on ListBox

大憨熊 提交于 2020-01-03 02:48:05
问题 Winforms' ListBox appears to have a strange behavior. When I set the SelectionMode to one, I expect that I can click an item, and it becomes selected. This holds true, but if I click an item, drag up and down the list, the selection changes. Now, that wouldn't be too much of a big deal except that I need to perform drag and drop between some controls. So, when they select an item, and drag it down the list, a newly-selected item is actually the one it registers as dragging, and the wrong item