What I have is two indexes. I want to select both the indexes from a ListBox but when I use SelectedIndex = count (that's where the index is stored), only the last index is selected. I have also tried using selectedItems.add(count) but the result doesn't show up. Here's my code:
if (checkedvalues_forclass[j] == subjectid_forreverse[count])
{
listBox1.SelectedItems.Add(count);
//or
listBox1.SelectedIndex=count;
}
Can anyone help me with this?
The solution to your problem is the following:
listBox1.SelectionMode = SelectionMode.Extended;
listBox1.SelectedItems.Add(listBox1.Items[firstindex]);
listBox1.SelectedItems.Add(listBox1.Items[secondindex]);
These two links might help you:
http://marlongrech.wordpress.com/2009/06/02/sync-multi-select-listbox-with-viewmodel/
http://www.gbogea.com/2010/01/02/mvvm-multiselect-listbox
Related
I am trying to figure out the best way to handle this. I have a series of form fields with checkboxes for people to select options. When that gets submitted it turns form.optiongroups into an array. I then check to see if the id of the optiongroup is in the array and set the checked value to true in case there were form errors I want them to retain their checked value. This all works fine.
If I only select one option though it doesn't come through as an array, but just a regular form field. Is there a way I can handle this to make sure it is always an array?
Actually, checkboxes get submitted as a list. You must have something else going on that creates the array.
However, to answer your question as asked, you can use ListToArray(). It would be something like this:
if (structkeyexists(form, 'optiongroups') { // if no boxes are checked the variable will be undefined.
if (isArray(form.optiongroups) == false )
form.optiongroups = ListToArray(form.optiongroups)
} else {
code for no boxes checked
}
It could also be done via...
param form.optiongroups = "";
form.optiongroups = ListToArray(form.optiongroups);
I am having different objects like in the code sample below. I have some checkboxes that filters based on brewer, style, aroma and country. It is filtering only if it has one property in the array.
What is the best solution to make the filter work based on all the elements in the array? I checked some other questions and I couldn't find anything related.
It will be great if any of you could help me.
Thanks.
sample of the code here: http://pastie.org/10787362
You could use filter method of Javascript Array() object.
For example:
$scope.filteredNames = $scope.names.filter(function(element) {
return
'brewer1' in element.brewers &&
'aroma1' in element.aromas
;
});
$scope.filteredNames should contain all names with 'brewer1' value in brewers property AND 'aroma1' value in aromas property...
Adding up on a post of 4 months ago which unfortunately didn't receive any answer.
I'm basically standing before the same problem when using multiselection in a datagrid with shift.
When in somewhere in the middle of a huge list (say it's 1,000,000 items in the grid, all data virtualized) and I were to select from 500,000 to 500,050 using shift + mouse click, the grid calls the "GetEnumerator()" method of my virtual list (similar implementation to Vincent's and Paul's). What I did until now was just a SelectMany on the cached pages. But unfortunately resulted in the rows not being properly selected (while ctrl + mouse click does the job!).
So what I found is, that the DataGrid actually expects all items from index 0 to the last of the selection. This, obviously, isn't ideal for a list of 1m items as this would result in requests for each and every item from 0 till (in my example) 500,050 and thus loading everything form database.
So my questions would be the same as those of Daniel in th elinked posted above:
Why does the DataGrid request items multiple times (selected items are requested ~6-7 times in a row for no apparent reason)?
Is there a way to tell the DataGrid not to use the Enumerator and to just take the items selected and not iterate through from 0 on?
Thank you very much, hoping I have more luck in getting at least thought provoking answers, as there isn't much to be found concerning data virtualization.
I found a solution to this problem (at least I can say it works for me).
What I basically did was fooling the VirtualList as such that I do the following code:
for (int i = 0; i < Count; i++)
{
int pageIndex = i/PageSize;
int pageOffset = i%PageSize;
IList<TItem> page;
if (pages.TryGetValue(pageIndex, out page))
{
yield return page[pageOffset];
}
yield return default(TItem);
}
That way I will always get the items that are really in the list, but return nothing when it is part of the virtualization.
Of course this can result in some other problems, but this is so far the closest I got concerning this.
I have a Devexpress XtraGrid with a total summary cell in the footer.
The cell is displayed correctly, but there is no value in it.
I have:
Grid.OptionsView.ShowFooter = true and Grid.OptionsBehavior.AutoUpdateTotalSummary = true.
In the column where I want the total sum I have:
Col.SummaryItem.FieldName = col.FieldName and col.SummaryItem.SummaryType = Sum and col.SummaryItem.DIsplayFormat = ${0}
The summery cell never shows a value.
If right click on the summary cell and then select Sum the summary value shows up and works correctly. But I need to work without the user needing to right click on the cell and select Sum.
Any help would be appreciated. Thanks :)
The following code works fine to me, so I believe that there is something wrong in your source code:
using DevExpress.Data;
using DevExpress.XtraGrid;
//...
colUnitPrice.FieldName = "UnitPrice";
colUnitPrice.Name = "colUnitPrice";
colUnitPrice.Summary.AddRange(new GridSummaryItem[] {
new GridColumnSummaryItem(SummaryItemType.Sum, "UnitPrice", "${0}")});
Please, check your source code again (don't forget to review the Total Summary article) or provide us with more details on this issue.
So far I've found 2 ways to delete selected items from a listbox (winform):
1.
ListBox.SelectedObjectCollection tempCollection = new ListBox.SelectedObjectCollection(myListBox);
for (int i = tempCollection.Count - 1; i >= 0; i--)
{
myListBox.Items.Remove(tempCollection[i]);
}
2.
while (myListBox.SelectedItems.Count > 0)
{
myListBox.Items.Remove(myListBox.SelectedItem);
// or
//myListBox.Items.Remove(myListBox.SelectedItems[0]);
}
The 2nd way is easy to understand, but the 1st one is strange for me. They're both work for me, I just want to know the difference?
The first way is written really strangely. It looks strange because it goes backwards. This is so that it doesn't upset the collection of selected items. The selected items collection isn't fully created, it's an Enumerable collection, and items come off it only when you ask for them. You can't use a foreach, because the collection of selected items keeps changing as you remove items.
I actually prefer the second way. Besides, whatever reads easier is easier to maintain. The first one reads: get the selected items, go through them backwards, removing each from the list.
The second one reads: while there are selected items, remove the first available selected item.
Much better the second way.