listbox

C# : change listbox items color

我与影子孤独终老i 提交于 2019-11-28 23:24:43
i am working on program on windows forms I have a listbox and I am validating data I want the correct data be added to the listbox with color green while the invalid data added with red color and I also want from the listbox to auto scroll down when an item is added and thanks code : try { validatedata; listBox1.Items.Add("Successfully validated the data : "+validateddata); } catch() { listBox1.Items.Add("Failed to validate data: " +validateddata); } Assuming WinForms, this is what I would do: Start by making a class to contain the item to add to the listbox. public class MyListBoxItem {

Multicolumn ListBox in WPF

倖福魔咒の 提交于 2019-11-28 23:12:55
I have 3 TextBoxes and 1 Button and want to enter each of the the TextBoxes data into a ListBox in separate columns. I know how to enter data into one column: listbox1.Items.Add(TextBox1.text); but how can I enter the data into multiple columns? I am using .NET WPF. I want to use a ListBox or a ListView . my window Ray You want a ListView instead: Something like this: <ListView ItemsSource="{Binding SourceCollection}"> <ListView.View> <GridView> <GridViewColumn Header="Test1" DisplayMemberBinding="{Binding Test1}" /> <GridViewColumn Header="Test2" DisplayMemberBinding="{Binding Test2}" />

Binding observable collection to ListBox in XAML

谁说我不能喝 提交于 2019-11-28 21:41:14
I've spent lots of hours with this problem. I have a class with data: public class User : INotifyPropertyChanged { private int _key; private string _fullName; private string _nick; public int Key { get{return _key;} set { _key = value; NotifyPropertyChanged("Key"); } } public string Nick { get { return _nick; } set { _nick = value; NotifyPropertyChanged("Nick"); } } public string FullName { get { return _fullName; } set { _fullName = value; NotifyPropertyChanged("FullName"); } } public User() { Nick = "nickname"; FullName = "fullname"; } public User(String nick, String name, int key) { Nick =

WPF Listbox auto scroll while dragging

孤街浪徒 提交于 2019-11-28 21:11:08
I have a WPF app that has a ListBox . The drag mechanism is already implemented, but when the list is too long and I want to move an item to a position not visible I can't. For example, the screen shows 10 items. And I have 20 items. If I want to drag the last item to the first position I must drag to the top and drop. Scroll up and drag again. How can I make the ListBox auto scroll? Artur Carvalho Got it. Used the event DragOver of the ListBox , used the function found here to get the scrollviewer of the listbox and after that its just a bit of juggling with the Position. private void

How can I find an item in a WPF ListBox by typing?

為{幸葍}努か 提交于 2019-11-28 20:56:06
Most list boxes allow you to find items within them by typing the first letters of the displayed text. If the typed letters match multiple items, then you can keep adding letters to narrow the search. I need to do this in a WPF ListBox . However, the items aren't plain strings -- they're custom objects that I present using a DataTemplate . I'm hoping that there's a way I can provide a path to the string value that should be used for this textual keyboard navigation of the ListBox items. How is this possible? You could try setting IsTextSearchEnabled to true and using the TextSearch.TextPath

ListBox Slide Animation On New Item Added

元气小坏坏 提交于 2019-11-28 20:36:45
问题 I am working on a news feed. This will update every so often and if new items are found, I want to slide in the new content from the top. Right now, I am just having it fade in by doing the following: <ListBox Grid.Row="0" Height="Auto" HorizontalAlignment="Stretch" Margin="5,5,5,5" VerticalAlignment="Top" ItemsSource="{Binding NewsItems,UpdateSourceTrigger=PropertyChanged}" > <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Style.Triggers> <EventTrigger RoutedEvent=

WP7 Auto Grow ListBox upon reaching the last item

China☆狼群 提交于 2019-11-28 19:55:22
I'm trying to achieve an effect where more items are appended to the list when the user scrolls down to the last item. I haven't found a way to determine if the user has scrolled to the end of the list. I don't see a event on ListBox that is fired when the user reaches the bottom of the list. Something that tells me when an item has been scrolled into view would be great, but as far as I can tell, there is nothing like that. Is this even possible in WP7? Edit: Another way of saying this is, can we detect when a list has "bounced"? Daniel Vaughan has posted an example of how to detect for this

How to create a listbox in HTML without allowing multiple selection?

点点圈 提交于 2019-11-28 19:25:07
问题 I don't have much experience in HTML. I am looking to create a simple listbox, but one of the requirements is to DISALLOW multiple selection. Most of the code for listboxes goes like this - <select name="sometext" multiple="multiple"> <option>text1</option> <option>text2</option> <option>text3</option> <option>text4</option> <option>text5</option> </select> But this allows for multiple selection. Here, a similar question was asked, but the "best" answer has been downvoted. So I am not sure

How can I get a vertical scrollbar in my ListBox?

风格不统一 提交于 2019-11-28 19:02:56
In the example below I have a ListBox with dozens of font names in it. I would have thought it would automatically have a vertical scrollbar on it so that you can select ANY font, not just the first ones in the list, but it doesn't. So I added a "ScrollViewer" and that puts a "scrollbar area" on the right but there is no scrollbar in the scrollbar area so that you can scroll (!). Why isn't a scrollbar automatic and how do I force it to have a scrollbar? <StackPanel Name="stack1"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="2*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>

Why is ListBoxFor not selecting items, but ListBox is?

安稳与你 提交于 2019-11-28 18:38:59
I have the following code in my view: <%= Html.ListBoxFor(c => c.Project.Categories, new MultiSelectList(Model.Categories, "Id", "Name", new List<int> { 1, 2 }))%> <%= Html.ListBox("MultiSelectList", new MultiSelectList(Model.Categories, "Id", "Name", new List<int> { 1, 2 }))%> The only difference is that the first helper is strongly typed (ListBoxFor), and it fails to show the selected items (1,2), even though the items appear in the list, etc. The simpler ListBox is working as expected. I'm obviously missing something here. I can use the second approach, but this is really bugging me and I'd