selecteditem

Cannot access the selected items collection when the ListView is in virtual mode?

寵の児 提交于 2019-12-09 00:43:06
问题 I have a ListView in Virtual Mode. I wanna to access SelectedItems property. But when I use ListView1.SelectedItems , I receive the following Exception : Cannot access the selected items collection when the ListView is in virtual mode How can I access to ListView1.SelectedItems in VirtualMode. 回答1: It is quite old post but maybe someone else will benefit. Simply use ListView.SelectedIndexCollection col = listView.SelectedIndices; Then you can access an item: forearch(var item in col) { string

Set SelectedItem on a combobox bound to datasource

懵懂的女人 提交于 2019-12-08 15:11:43
问题 List<Customer> _customers = getCustomers().ToList(); BindingSource bsCustomers = new BindingSource(); bsCustomers.DataSource = _customers; comboBox.DataSource = bsCustomers.DataSource; comboBox.DisplayMember = "name"; comboBox.ValueMember = "id"; Now how do I set the combobox's Item to something other than the first in the list? Tried comboBox.SelectedItem = someCustomer; ...and lots of other stuff but no luck so far... 回答1: You should do comboBox.SelectedValue = "valueToSelect"; or comboBox

Windows Phone 7: ListBox SelectionChanged event

我与影子孤独终老i 提交于 2019-12-08 12:55:32
问题 I'm new to XAML and Windows Phone 7 SDK. I'm developing an Windows Phone 7 application and I don't know how to detect selected item from the ListBox. I'm using panorama template, here is my code: <controls:PanoramaItem Header="Basic"> <ListBox Margin="0,0,-12,0" Name="MyListBox" SelectionChanged="Elementary_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> <Image Height="100" Width="100" Source="{Binding LevelPassedImage}" Margin=

pre-selected items in CActiveForm->checkBoxList in Yii

落花浮王杯 提交于 2019-12-08 06:15:08
问题 I have two arrays. One is $categories which contains all categories retrieved from my db and the other is $preSelectedCategories which contains the categories that needs to be pre-selected in my check box list when my form is loaded. I tried to do this: <?php echo $form->labelEx($model,'category_id'); ?> <?php echo $form->checkBoxList($model, 'category_id', $categories, $preSelectedCategories, array('multiple'=>true)); ?> <?php echo $form->error($model,'category_id'); ?> But I did not succeed

How can I get the position of a row in a dataset in order to set the selected item in an Android Spinner?

心已入冬 提交于 2019-12-08 01:32:35
问题 I have a Spinner that's populated using a cursor containing data from a database. It appears that it's impossible to set the selected item in the spinner using the value of the ID column of a row. And that the only way to set the selected item is by using the position of the row within the dataset. Is this correct? If so, is there a more efficient way of determining the row's position than by iterating through the dataset using the cursor? The inefficient (to my mind) way is outlined here.

How to set SelectedItem of a ComboBox when item is not part of the ItemsSource collection?

让人想犯罪 __ 提交于 2019-12-07 18:20:00
问题 Following scenario: <ComboBox ItemsSource="{Binding Path=Names}" SelectedItem="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"> </ComboBox> Names is a string collection which might change through code in the ViewModel. For example Names could be set to either male names (John, Paul, George) or female names (Mary, Jane, Karen). Let's assume the male collection is active and the user selects "John" making it the SelectedItem. Now the collection changes to female names. By default the

ComboBox Style problems with DisplayMemberPath

我怕爱的太早我们不能终老 提交于 2019-12-07 09:30:16
问题 I have a ComboBox and I have set the combo.ItemsSource property to a List object. The Book class contains two properties: "Abbreviation" and "Name". I have set the ComboBox's DisplayMemberPath to " Abbreviation " but the following style that is set on the ComboBox does not display the Abbreviation property, but instead shows " Words.Book " which is the name of the class. The ComboBox drop-down displays a list correctly (Using the specified Abbreviation property). The problem is in the

How to ensure that no item is selected in databound ListBox?

时光怂恿深爱的人放手 提交于 2019-12-07 07:56:49
问题 OK, this must be a duplicate question, but I cannot find the answer: I have a listbox that is databound to a Collection. By default Items[0] is selected. How can I prevent this in order to ensure that the SelectionChanged event is raised any time I click a ListBoxItem? EDIT: I had already dismissed the SelectedIndex=-1 route, but I tried again: Setting the SelectedIndex to -1 in the Listbox's constructor (or as an attribute in XAML) does not work. It seems that the listbox is populated after

FindByValue on ASP.NET DropDownList

狂风中的少年 提交于 2019-12-07 06:58:16
问题 I have the following code in a custom user control that contains a DropDownList named ddlAggerationUnitId. The DropDownList is DataBind'd on the Page_Load() event. The "value" is set to be 40 and it DOES exist. If I remove the logic for the set method the page will load and select the correct item, but if the value is bogus the page throws an exception. I'd like to avoid that exception by seeing if the value exists BEFORE trying to set it, hence why the logic is necessary. Right now it looks

Getting ValueMember from selected item in a ListBox with C#

依然范特西╮ 提交于 2019-12-07 03:30:30
问题 I'm trying to get all the selected items ValueMember from a ListBox with C#. For ex.: I've a list like this: ID | Name and Lastname ---------------------- 1 | John Something 2 | Peter Something2 3 | Mary Smith This structure is part of my ListBox. I've builded this listbox with this code: private void fill_people_listBox() { this.listBoxPeople.DataSource = db.query("SELECT ...."); this.listBoxPeople.DisplayMember = "people_name_last"; this.listBoxPeople.ValueMember = "people_id"; } The