Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Update value in a collection

$
0
0

I have a DataGrid with an item source as an observable collection. At button click on of the value in a column of the current row gets increased by 1.  So I went to solve it this way;

ItemRow currentRow = (ItemRow)myDataGrid.SelectedItem;
newQty = currentRow.qty + 1;
newExtPrice = newQty * currentRow.price;

myCollection.Remove(currentRow);
myCollection.Add(new ItemRow { itemid = currentRow.itemid, qty = newQty });

The problem is that the DataGrid view order gets changed.  So for example say there were 4 rows in the grid and the user clicks on the first row, that row is removed and placed at the bottom.  What is the better way to handle this?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>