selecteditem

How to get the latest selected value from a checkbox list?

佐手、 提交于 2019-11-27 21:29:28
I am currently facing a problem. How to get the latest selected value from a asp.net checkbox list? From looping through the Items of a checkbox list, I can get the highest selected index and its value, but it is not expected that the user will select the checkbox sequentially from lower to higher index. So, how to handle that? Is there any event capturing system that will help me to identify the exact list item which generates the event? If I understood it right, this is the code I'd use: protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) { int lastSelectedIndex = 0

How to cast a System.Windows.Controls.SelectedItemCollection?

社会主义新天地 提交于 2019-11-27 20:06:19
问题 I have a method: private void DeletePuzzle(object param) { } param is a System.Windows.Controls.SelectedItemCollection , that I got from a WPF ListView 's SelectedItems property. Somehow, I can't seem to cast it from an object to anything useful. I can't create a System.Windows.Controls.SelectedItemCollection because of its protection level, and param won't cast to IList , ICollection or IEnumerable . How can I iterate through param's items? 回答1: Right, got it sorted. I kept trying to cast it

Reset combobox selected item on set using MVVM

丶灬走出姿态 提交于 2019-11-27 15:10:01
I am using a ComboBox in my WPF application and following MVVM. There is a list of strings which I want to show in my ComboBox. XAML: <ComboBox ItemsSource="{Binding ItemsCollection}" SelectedItem="{Binding SelectedItem}" /> View Model: public Collection<string> ItemsCollection; // Suppose this has 10 values. private string _selectedItem; public string SelectedItem { get { return _selectedItem; } set { _selectedItem = value; Trigger Notify of property changed. } } Now this code is working absolutely fine. I am able to select from view and I can get changes in ViewModel and if I change

WPF ListView SelectedItem is null

纵然是瞬间 提交于 2019-11-27 15:05:10
I have a Listview that has a checkbox as one of the columns. If I click anywhere but the actual checkbox the SelectedItem of the ListView is set to the current selected row, as expected. If, on the other hand I click onto the checkbox (without clicking on the row first) then the SelectedItem is null or the previously clicked row. Can anyone help me out.... Cheers <ListView Width="auto" SelectionMode="Single" x:Name="listBox" ItemsSource="{Binding MyData}" SelectedItem="{Binding Path=SelectedMyData}"> <ListView.View> <GridView> <GridViewColumn Header="Date" Width="120"> <GridViewColumn

ComboBox ItemsSource changed => SelectedItem is ruined

。_饼干妹妹 提交于 2019-11-27 13:50:24
问题 Ok, this has been bugging me for a while now. And I wonder how others handle the following case: <ComboBox ItemsSource="{Binding MyItems}" SelectedItem="{Binding SelectedItem}"/> The DataContext object's code: public ObservableCollection<MyItem> MyItems { get; set; } public MyItem SelectedItem { get; set; } public void RefreshMyItems() { MyItems.Clear(); foreach(var myItem in LoadItems()) MyItems.Add(myItem); } public class MyItem { public int Id { get; set; } public override bool Equals

Select item programmatically in WPF ListView

橙三吉。 提交于 2019-11-27 13:35:05
I'm unable to figure out how to select an item programmatically in a ListView. I'm attempting to use the listview's ItemContainerGenerator, but it just doesn't seem to work. For example, obj is null after the following operation: //VariableList is derived from BindingList m_VariableList = getVariableList(); lstVariable_Selected.ItemsSource = m_VariableList; var obj = lstVariable_Selected.ItemContainerGenerator.ContainerFromItem(m_VariableList[0]); I've tried (based on suggestions seen here and other places) to use the ItemContainerGenerator's StatusChanged event, but to no avail. The event

Getting selected value of a combobox

你离开我真会死。 提交于 2019-11-27 12:37:37
public class ComboboxItem { public string Text { get; set; } public string Value { get; set; } public override string ToString() { return Text; } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = comboBox1.SelectedIndex; int selecteVal = (int)comboBox1.SelectedValue; ComboboxItem selectedCar = (ComboboxItem)comboBox1.SelectedItem; MessageBox.Show(String.Format("Index: [{0}] CarName={1}; Value={2}", selectedIndex, selectedCar.Text, selecteVal)); } I'm adding them like: ComboboxItem item = new ComboboxItem(); item.Text = cd.Name; item.Value = cd.ID;

How do you programmatically set focus to the SelectedItem in a WPF ListBox that already has focus?

折月煮酒 提交于 2019-11-27 12:21:08
We want to set the SelectedItem of a ListBox programmatically and want that item to then have focus so the arrow keys work relative to that selected item. Seems simple enough. The problem however is if the ListBox already has keyboard focus when setting SelectedItem programmatically, while it does properly update the IsSelected property on the ListBoxItem , it doesn't set keyboard focus to it, and thus, the arrow keys move relative to the previously-focused item in the list and not the newly-selected item as one would expect. This is very confusing to the user as it makes the selection appear

Get SelectedItem from TreeView?

浪尽此生 提交于 2019-11-27 07:28:45
问题 Does anyone know how I can get the SelectedItem (not the Header) from a TreeView? Here is my code: <TreeView Name="treeView1" DataContext="{Binding Path=PresentationsViewModel}" Grid.Column="1" > <TreeViewItem IsExpanded="True" Header="Objects-A-List" DisplayMemberPath="Name" ItemsSource="{Binding Path=MyItem.ListA}"></TreeViewItem> <TreeViewItem IsExpanded="True" Header="Objects-B-List" DisplayMemberPath="Name" ItemsSource="{Binding Path=MyItem.ListB}"></TreeViewItem> <TreeViewItem

WPF Binding SelectedItem in DataGrid

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:39:24
问题 So, I have a TabControl binded to a list of projects (each tab is a one project) - that works fine. The content of each tab is a DataGrid with a list of project's employees - that works fine as well. Now, I want to show some information on employee currently selected on DataGrid. Here's some code: MainWindow.xaml file: <Window.Resources> <DataTemplate x:Key="ItemTemplate"> <TextBlock Text="{Binding Name}" /> </DataTemplate> <DataTemplate x:Key="ContentTemplate"> <DataGrid ItemsSource="