listbox

How can you stop an expander in a list box from collapsing when data changes?

I have a screen with a ListBox of items. The item template contains an expander control with some of the data in the header and some of the data in the content part of the expander. The data template for the ListBox ItemTemplate is similar to this: <DataTemplate x:Key="MyTypeTemplate" DataType="{x:Type MyType}"> <Expander DataContex...

How can I add a context menu to a ListBoxItem?

I have a ListBox and I want to add a context menu to each item in the list. I've seen the "solution" to have the right click select an item and suppress the context menu if on white space, but this solution feels dirty. Does anyone know a better way? ...

C# How do I do I loop through items in a list box and then remove that item?

Hi All, I'm getting the error below when trying to loop through a listbox and then remove the item. "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change." foreach (string s in listBox1.Items) { MessageBox.Show(s); //do stuff with (s); listBox1.Items.Remove(s); } How ...

What is the most efficient way to filter listboxes based on selections of another in c#?

I have several listboxes that get each of their data from a separate stored procedure. If the user selects an option in 1 listbox, it should filter the other listboxes. I have done this before by adding logic to the stored procedure, but sometimes it seems to get very long. Does anyone know of a better way to approach this? T...

WPF ListBox DataTemplate and Image Question

I have a ListBox with a StackPanel that contains an image and label. <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> ...

WPF ListBox Image Selected the saga continues

Ok in my ListBox scrolling images w/ text, etc. the saga continues. When I click one of the items, to select it, that runs a process to open a web browser and go to a specific URL. The problem I'm having now is that when the WPF app loses focus, and the web browser opens, the item clicked inside the listbox turns white. Here's the whole ...

WPF ListBox Can you make it cycle? IE not hit hard stops at top and bottom

I have a WPF ListBox bound to a data object. Inside the listbox are a series of images with text. It is layed out in a horizontal fashion, and mousing over the left or right sides of the box scroll the items left or right respectively. let's say there are 20 items in the listbox. I'm trying to figure out how when I hit position 19 item ...

Is there a WPF ListBox equivalent to Windows Forms Listbox TopIndex?

Basically what I want to do is allow a user to type in a string value and have the list box scroll to the item that matches the text they have typed (or the first LIKE match). If I use the .ScrollIntoView() method, the problem is that it puts the item at teh bottom of the visible area if the item is further down in the list than the cur...

DataBound WPF ListBox Styling on ListBoxItems

I have a listbox that during development I had the items in the list box hardcoded and styled. This is how the items were styled. <ComboBoxItem Width="Auto" Height="Auto" Content="ComboBoxItem" > <ComboBoxItem.Foreground> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"...

Force textblock to wrap in WPF listbox

I have a WPF listbox which displays messages. It contains an avatar on the left side and the username and message stacked vertically to the right of the avatar. The layout is fine until the message text should word wrap, but instead I get a horizontal scroll bar on the listbox. I've Googled and found solutions to similar issues, but no...

ListBox with overriden CreateParams doesn't raise item events

Hi, I've created a custom ListBox like in here. Thing is it doesn't raise any of the item specific events like DrawItem and SelectedIndexChanged. Any idea why? Thanks. ...

OpenGl ES scrollable ListBox clipping problem

Hello, I am trying to create a generic list box in OpenGl ES (for the iPhone/iTouch) and I am running into a bit of a conundrum with clipping the ListBoxItems. Each ListBoxItem object will know how to draw itself. The ListBox I am making will just draw each one after another. But what if the number of items is larger than the ListBox? ...

How Can I Get the Index of An Item in a ListBox?

I am adding items to a ListBox like so: myListBox.Items.addRange(myObjectArray); and I also want to select some of the items I add by the following: foreach(MyObject m in otherListOfMyObjects) { int index = myListBox.Items.IndexOf(m); myListBox.SelectedIndices.Add(index); } however index is always -1. Is there a different...

C# How do I check a selected item in a listbox using code?

I have a listbox with checkboxes, how do I check the checkbox of the selecteditem? Thanks ...

When I move through a list box, why do my checked items become unchecked?

The code below moves the selected item in the listbox downwards to the next item in the listbox, but it unchecks the selected item if it was checked. How can I prevent this? private void buttonMoveDown_Click(object sender, EventArgs e) { int iIndex = checkedListBox1.SelectedIndex; if (iIndex == -1) { return; } moveL...

TwoWay Manual Binding Implementation for ListBox.SelectedItems?

Hello, I've been trying to see if there is an easy/clever way to implement binding to ListBox.SelectedItems. If you have tried yourself, you will know, that markup binding using BindingExtension will not work - the property doesn't support it. So you are left with wiring up a handler for SelectionChanged and trying that route. The close...

Filtering With Multi-Select Boxes With SQL Server

I need to filter result sets from sql server based on selections from a multi-select list box. I've been through the idea of doing an instring to determine if the row value exists in the selected filter values, but that's prone to partial matches (e.g. Car matches Carpet). I also went through splitting the string into a table and joini...

C# How do I run some code for the selected item in a listbox?

I have a listbox of names, I want to click one of the names so that it is highlighted and then click a button that runs some code for the selected item. How do I call this selected item? private void btnEcho_Click(object sender, EventArgs e) { listbox1.SelectedItem...... } Many thanks ...

How to filter the following listboxes in asp.net?

I have 4 listboxes (lstStates, lstCounties, lstCities, and lstZipcodes). Here are a few constraints: None of the listboxes are disabled. Any listbox can be selected at anytime, meaning there is no specific order the user has to choose. Filtering is forward and backwards. By this, I mean if a user selects a state from lstStates, it wi...

How to center a WPF CheckBox within a ListBoxItem

I have a ListBox that uses an ItemContainerStyle. I have tried everything I can think of to get a CheckBox control to center vertically and horizontally. Any ideas? <ListBox IsSynchronizedWithCurrentItem="True" Height="Auto" Width="Auto" DockPanel.Dock="Top" ItemContainerStyle="{StaticResource lbcStyle}" /> <Style TargetType="Li...