您好我试图在点击时获取第二列值并显示在文本框中但我对C#来说真的很新。
private void DataGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
display.Text = Datagrid.SelectedItem.ToString();
}
这显示所有列,但我只想要第二列,第二列colummn标题是Name。
var query = from loan in Loans
select new {Date = loan.StatusCommittedDate, Name = loan.PublicationName}
DataGrid.ItemsSource = query.ToList();
答案 0 :(得分:0)
根据您的数据网格绑定方式,这可能有效
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;
}
}
希望这有帮助