Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Can't Select Items in Datagrid after adding it to the ObservableCollection
    primarykey
    data
    text
    <p>I have a datagrid in my view that is bound to an ObservableCollection in my viewmodel, the issue that I am having is that after I programmtically add an a new Item to my ObservableCollection it appears in the Datagrid however I "Can and Cannot" select it, I know its a sounds a bit wacky but bear with me. In code its somthing along the lines of:</p> <pre><code>&lt;DataGrid Grid.Column="0" AutoGenerateColumns="False" ItemsSource="{Binding Path=MyList} SelectedValue{Binding Path=SelectedMyItem}... &gt; &lt;/Datagrid&gt; </code></pre> <p>Then in my viewmodel:</p> <pre><code> private ObservableCollection&lt;MyType&gt; myList; public ObservableCollection&lt;MyType&gt; MyList { get { return myList;} } privte void AddItem(MyType item) { myList.Add(item) } public MyType SelectedMyItem {get;set;} </code></pre> <p>Now what happens is the Datarid gets updated and the new items appears in the grid. However when I try to select it, the grid highlights the previous item in the list, but the black border (that a selected item gets) appears around the new item. Aswell my SelectedValue Binding gets set to the new item. I have also created a context menu that allows user to delete items and when I right click and try to delete the newly added item, it instead deletes the previous item in list.<br /> However when this happens I am then able to properly select the new item. So I am guessing I need away to to refresh the datagrid I am assuming(note if I trigger INotifyPropertyChanged for MyList the sane thing still happens) </p> <p><strong>EDIT:</strong></p> <pre><code>public override bool Equals(object obj) { var o = obj as MyType; if (o == null) return false; return o.MyTypeId == this.MyTypeId; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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