Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have recently switched to WPF from WinForms so please excuse my noobness.

I have a grid is being populated by an Observable Collection. I have menu buttons that are supposed to add and remove entries from the collection. Adding the rows was easier, now i'm having trouble trying to remove an entry.

First, the User will select the row, then click the delete button. I am trying to determine which row they have selected in the datagrid. I have been trying code such as Grid.CurrentCell.ToString() or Grid.DisplayMemberValue.ToString() but I cannot seem to get the current cell value. It returns a blank value or a generic name for the row. Even if I could determine the index, I could build it from that.

Thank you,
Posted

1 solution

Look at the SelectedItem Property[^]
or SelectedValue Property[^] with the SelectedValuePath Property[^].
For the Add and Delete operations you should use commands, and the item to add or delete should be provided as command parameter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900