如何在wpf中的文本框中显示datagrid selected coloum [英] how to display datagrid selected coloum in textbox in wpf
本文介绍了如何在wpf中的文本框中显示datagrid selected coloum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我选择要在文本框中显示的选定值的行时,我向数据网格添加了一个coloum。
我尝试了e.addeditems [0] .Tostring()在datagrid中选择了更改事件;它返回as object [0]然后我如何将一个对象转换为字符串并添加到文本框。
i我是wpf的新手,任何人都可以建议。
提前感谢
i added a coloum to datagrid when i select a row that selected value i want to display in textbox.
forthat i tried e.addeditems[0].Tostring() in datagrid selected change event; it returns as object[0] then how i convert an object to string and add to textbox.
i am new to wpf can any one please suggest.
thanks in advance
推荐答案
尝试这种方式..
Try this way..
private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
object item = dataGrid1.SelectedItem; //probably you find this object
string ID = (dataGrid1.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
MessageBox.Show(ID);
}
或,
Or,
string ID = ((DataRowView)dataGrid1.SelectedItem).Row["ID"].ToString();
这也做同样的事情。
This also do the same thing.
这篇关于如何在wpf中的文本框中显示datagrid selected coloum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文