0

Hi I'm trying to grab the second column value on click and to display in a text box but im really new to C#.

private void DataGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)  
{  
   display.Text = Datagrid.SelectedItem.ToString();  
}  

This displays all columns, but i only want second column, the second colummn header is Name.

var query = from loan in Loans  
        select new {Date = loan.StatusCommittedDate, Name = loan.PublicationName}  

DataGrid.ItemsSource = query.ToList();
user2785177
  • 69
  • 1
  • 10

1 Answers1

0

Based on how your datagrid is binded this may work

private void DataGrid_SelectionChanged(object sender, SelectionChangeEventArgs e) {

    DataGrid dataGrid = sender as DataGrid;

    int selectedIndex = dataGrid.SelectedIndex;

    if (selectedIndex > -1)
    {

        DataGridColumn column = dataGrid.Columns[0];
        Label lblName = (Label)column.FindControl("ControloftheIDwithPublicationNameBinded");
        display.text = lblName.text;
     }
 }

Hope this helps

Matthew Wong
  • 274
  • 1
  • 7