How to read value from cell from WPF DataGrid?

How to read cell value from WPF DataGrid?

I search the Internet and try any possible combination, and nothing works:

Datagrid.Cells [..], DataGrid.Items.Cells [..], DataGrid.Rows .., DataGrid.Items.Row .. nothing works, I can not find MSDN, or I do not understand this. I just need to just read the value from the cell in the DataGrid.

How to do it?

+4
source share
4 answers

It may help someone else.

foreach (DataRowView row in dgLista.SelectedItems) { string text = row.Row.ItemArray[index].ToString(); } 

Good luck

+1
source

Here is a brief description of the solution.

Winform

Type: System.windows.Forms.DataGridView

 // C# foreach (DataGridViewRow row in dataGridView1.Rows) { //"Column1" = column name in DataGridView string text = row.Cells["Column1"].value.ToString(); } 

WPF equivalent

Type: DataGrid

 // C# foreach (DataRowView row in dataGrid.Items) { string text = row.Row.ItemArray[index].ToString(); } 
+1
source

The following helped me:

 Private Sub dgNames_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles dgNames.MouseDoubleClick Dim strCellContent as String = MessageBox.Show(TryCast(e.OriginalSource, TextBlock).Text) End Sub 
0
source

Source: https://habr.com/ru/post/1346695/


All Articles