I need to display a list of items in list picker,Im using list picker with multiple selection mode.Is there any way to check the check boxes of multiple items from c#(without user's interaction).I found many ways to find the list of selected items but couldnt find how to set multiple items as selected from code behind.Please help.I tried using
for(int i=0;i<selecteditems.count;i++)
{
listpicker.SelectedItem=listpicker.Items[i];
}
This doesnt work ..
Use the SelectedItems property for setting multiple items as selected.
This may be help you
listpicker.SelectedItems = List<your selected items>;
Related
I would like to create groups by day for my items in a ListView (like a LongListSelector in WP7). I succeed with alphabetical items thanks to the CharacterGroupings class but I try to find the best way with timestamp. Do you have any idea to help me sorting items by creating by month/day, then put all the relating items in these groups ?
Here's my problem: I need to make a DataGrid with dynamic comboboxes using the WPF. If the value of a combobox is already used in the previous rows, the next ones, that will be added by the user, shouldn't contain the item already used.
In this image, the ITEM A shouldn't apear on the combobox of the second line.
I don't have ideia how to accomplish this, can anyone show me a light?
OBS: The DataGrid ItemsSource is binded to an ObservableCollection, and the DataGridComboBoxColumn ItemsSource is a List.
Thanks !!!
The ItemsSource of the combo doesn't have to be bound to an ObservableCollection, but it can help depending on exactly how you solve this.
When that cell goes in to edit mode the property the ItemsSource is bound to gets hit - so you can return a new list of items each time the getter is hit. Here is a very basic example to give you an idea:
public List<string> MyItemsSource
{
get
{
var myNewList = MyMasterList.ToList(); //create a (reference) copy of the master list (the items are not copied though, they remain the same in both lists)
if (PropertyA != null)
myNewList.Remove(PropertyA);
return myNewList;
}
}
So what you are creating and returning is a filtered version of your master list of all possible items. LINQ will be of great help to you here.
Alternatively you could keep just one static copy of the master list as an ObservableCollection, and simply remove items from that static copy as they get selected (and add them back in as they get unselected). Which option you choose will depend on how many times the list can be modified due to items being selected and how complicated it is to generate the list. I've used the dynamically generated list many times in the past, it's an option that works well in most cases.
I have 2 listboxes each displaying 2 different lists which are being populated by user input. I was wondering if I could somehow combine the data in each listbox and show it in a third listbox. This is a windowsForms application in visual Studio. I also want to make sure that it is updated properly when a new value is added into the 2 different listboxes. So far what I have done is combined the two lists that I have as so:
public List<String> listAll()
{
List<String> all = new List<string>();
all.AddRange(listFirstName());
all.AddRange(listSecondName());
return all;
}
The problem with this is first of all i dont know if this will update when a new value is added to the other two lists. and secondly now that I have this new list i still dont know how to display it in a listbox. keep in mind that i still need to have the other listboxes containing the first 2 lists displayed in the main form along with this new listbox which will contain the values for both of them.
Cheers, any help is welcome and appreciated.
You can have seperate method to populate listBox3. in that method you can clear existing items and add all the items from listBox1 and listBox3.
when you add items to listBox1 or listBox2 you can call same method after adding items.
listBox3.Items.Clear();
listBox3.Items.AddRange(listAll().ToArray());
Usually, if you want to make sure that your Listbox updates dynamically, use an ObservableCollection instead of a List.
ObservableCollection has the same format as a List:
ObservableCollection<String> all = new ObservableCollection<string>();
Make sure you add the following
using System.Collections.ObjectModel;
I have a drop down list whose4 datasoruce is already set, I need to add an extra item, in webapplications it's easy, using Items.Insert(index, newItem). but in windows applications it is not working, any body can help!
Note: I need to add the items without affecting the datasource at all
thanks
If your DataSource doesn't have an Add method. You will have to either create your own DataSource (List<...>) or add item iteratively.
If the data source is a dataset or list, try adding items to it and those will appear in the drop down.
I am using XtraGrid in my application. Now, I want to display only Unique values for particular column when user will click filter button. I want to display this list check box items initially all checked. Also I want the information that what items user has selected/deselected from from checked list box.
Any idea?
I think you need to implement a custom filter dialog, as described here:
http://documentation.devexpress.com/#WindowsForms/CustomDocument698