Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get WPF DataGrid Selected Cell Value?

Tags:

c#

wpf

datagrid

In my C# wpf application i have taken a DataGrid which is bounded by a datatable from database. All values are displayed in this DataGrid. But i want to get the selected cell value.

Here is my code which is bounded by datatable:

dataGrid1.ItemsSource = datatable1.DefaultView; 

Please give me a solution to find the cell value. I have found selected index by following code:

dataGrid1.SelectedIndex
like image 729
Refat Sardar Avatar asked Dec 04 '25 06:12

Refat Sardar


1 Answers

Assuming that you are editing a DataGridTextColumn cell...

Use e which is in the dataGrid1_CellEditEndingEvent like so:

((TextBox)e.EditingElement).Text

This will give you the typed text.

like image 136
user980150 Avatar answered Dec 05 '25 23:12

user980150



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!