Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the databinding fails in ListView (WPF)?
    text
    copied!<p>I have a ListView of which ItemSource is set to my Custom Collection.</p> <p>I have defined a GridView CellTemplate that contains a combo box as below :</p> <pre><code> &lt;ListView MaxWidth="850" Grid.Row="1" SelectedItem="{Binding Path = SelectedCondition}" ItemsSource="{Binding Path = Conditions}" FontWeight="Normal" FontSize="11" Name="listview"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="175" Header="Type"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox Style="{x:Null}" x:Name="TypeCmbox" Height="Auto" Width="150" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding Path = MyType}" ItemsSource="{Binding Path = MyTypes}" HorizontalAlignment="Center" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/ListView&gt; public MyType : INotifyPropertyChanged </code></pre> <p>{ string Key; string Value;</p> <pre><code>public string Key { get { return _key; } set { _key = value; this.OnPropertyChanged("Key"); } } public string Value { get { return _value; } set { _value = value; this.OnPropertyChanged("Value"); } } public MyType () { } public MyType (string key, string value) { _key = key; _value = value; } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } #endregion </code></pre> <p>}</p> <pre><code> public void MoveUpExecuted() { int oldIndex = this.Conditions.IndexOf(_selectedCondition); //Check if the selected item is not the first item if (oldIndex != 0) { int newIndex = oldIndex - 1; this.Conditions.Move(oldIndex, newIndex); } } </code></pre> <p>My Custom collection is the ObservableCollection.</p> <p>I have a two buttons - Move Up and Move Down on top of the listview control . When user clicks on the Move Up or Move Down button I call Move method of Observable Collection.</p> <p>But when I Move Up and Move Down the rows then the Selected Index of a combo box is -1.</p> <p>I have ensured that selectedItem is not equal to null when performing Move Up and Move Down commands.</p> <p>Please Help!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload