selecteditem

Find the Index of the Selected Object

我只是一个虾纸丫 提交于 2019-12-11 06:44:52
问题 Given an object Foo which has the method bool isChecked() const . Let's say that I have Foo foos[] . I am guaranteed that exactly one element of foos will return true on isChecked() , all others will return false . I'm looking for a clever C++03 way to find the index of the true element. I can do this but it's pretty ugly. Does anyone have something better? distance(foos, find_if(foos, foos + SIZE, mem_fun_ref(&Foo::isChecked))) #include <algorithm> #include <functional> #include <iostream>

WPF Datagrid selecteditem = null in MVVM

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:43:54
问题 I'm trying to work with a datagrid using the MVVM pattern. The problem is that whenever I change the VM property which is binded to SelectedItem to null, the View doesn't "deselect" the currently selected item. This is my binding in xaml: <DataGrid Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Path=Users}" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True" SelectedItem="{Binding Path=SelectedUser, Mode=TwoWay}"> The SelectedItem binding works from the view to the VM

ASP.NET, VB: checking which items of a CheckBoxList are selected

≯℡__Kan透↙ 提交于 2019-12-10 22:58:12
问题 I know this is an extremely basic question, but I couldn't find how to do this in VB... I have a CheckBoxList where one of the options includes a textbox to fill in your own value. So I need to have that textbox become enabled when its checkbox (a ListItem in the CheckBoxList) is checked. This is the code behind, I'm not sure what to put in my If statement to test if that certain ListItem is checked. Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System

Object binding to Winforms ComboBox fails when SelectedItem is null

偶尔善良 提交于 2019-12-10 18:55:42
问题 I found a lot of posts that dodge this topic, but none that actually addresses this case. I have a ComboBox bound to a List<State> , where State is a business object that has Abbreviation and Name properties: this._stateComboBox.DataSource = ((Address)this._addressBindingSource.DataSource).States; this._stateComboBox.DisplayMember = "Abbreviation"; this._stateComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this._addressBindingSource, "State")); Initially the

Why is my DropDownList's SelectedItem not working?

心已入冬 提交于 2019-12-10 17:07:34
问题 I am having a problem with an ASP.NET DropDownList which is populated by an XML file: rblState.DataSource = dsState; rblState.DataValueField = "abbreviation"; rblState.DataTextField = "name"; rblState.DataBind(); This works fine and displays all the right data however, the problem occurs when I try and retrieve the selected value from the list after a button has been clicked: string state = rblState.SelectedItem.Text; Console.WriteLine(state); This always outputs only the first value within

Problem with data binding (Using the MVVM pattern) to a WPF Combobox within a DataGrid's RowDetailsTemplate

笑着哭i 提交于 2019-12-10 12:18:21
问题 I'm trying to bind a view model property to the 'SelectedItem' attribute of a WPF combobox. This combobox resides within a RowDetailsTemplate of a DataGrid. The binding is partially there because the view model's property getter and setter each get called once when a row is selected (And thus causes the details view to expand). However the property never gets called again upon subsequent combobox selection changes. It's almost like the data context is not right after the row details is

Change WPF UserControl depending on a Property of a TreeViewItem

本秂侑毒 提交于 2019-12-10 11:38:01
问题 My application shows a TreeView on the left with hierarchical ordered items which are all the same type. All the items have a dependency property which can have one of two values. This value is an enum. Depending on this value I want to show one of two UserControls on the left. My idea was to insert both controls and set their opacity to 0. Then I wanted to insert a Style with a DataTrigger that triggers the opacity depending on the enum's value. But I can not access the properties of one

How to keep an item selected? - ListView

烈酒焚心 提交于 2019-12-10 00:26:44
问题 I would like to keep an item selected, on a ListView, when the user clicks on a space which has no item. For example, the space below the items, but still on the ListView component. I've change the ListView property "HideSelection" to false, but that only works when the focus is changed to another component; not when the user clicks on the ListView itself. Thanks! 回答1: This is something you normally shouldn't fix. The user clicked somewhere intentionally, that might well be because she wanted

Prevent WPF ListBox from selecting item under mouse when layout changes

末鹿安然 提交于 2019-12-09 18:38:32
问题 If a WPF ListBox gets a MouseMove event while the mouse button is held down, it will change the listbox's selection. That is, if you click the mouse on item #1, and then drag over item #2, it will deselect item #1 and select item #2 instead. How can I prevent this? That's the short version. The slightly longer version is this: When the user double-clicks an item in my ListBox, I make other changes to my layout, which includes showing other controls above the ListBox. This moves the ListBox

AngularJS - setting selected value of dropdown does not work

偶尔善良 提交于 2019-12-09 10:32:37
问题 I made a fiddle replicating my problem here: http://jsfiddle.net/U3pVM/2840/ As the title suggests, I can't set the selected value of a select populated using ng-options. I have searched and tried all possible solutions that I found. Any help or suggestions would be appreciated! HTML <div ng-app> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <select ng-model="ddlRooms" ng-options="r.id as r.Name for r in Rooms"> </select> {{$scope.test}} </div> </div> Angular function TodoCtrl($scope) { $scope