-1

I found only solutions with manual created datagrid with binding.

Idk how to do it when I am getting data from SQL.

Let's say that I would need:

FIRSTNAME  LASTNAME   TELEPHONE
 TestFi     TestLa     1111111
 Testfa     TestAl     2222222

When I mouse click on first record in datagrid I would like to print only telephone.

Problem is that I am not even getting any data while using:

MessageBox.Show(dg.SelectedItem.ToString());

In messagebox it shows:

System.Data.DataRowView

Could anyone say me why is that happening?

Cabry
  • 125
  • 12
  • Sorry for duplicate. Every time I am googling as much as I can. I did not find original question. – Cabry Jan 29 '19 at 10:08

1 Answers1

0

Your SelectedItem is a DataRowView. So, you have to choose the column to display :

var row = (DataRowView)dg.SelectedItem;
MessageBox.Show(row["phone"]);
Clemens
  • 123,504
  • 12
  • 155
  • 268
Tom
  • 38
  • 7