0
我想返回單元格0的值,我在一個DataGrid中雙擊一行。到目前爲止,我可以從所有行中返回單元格0的值,但我只想要雙擊該行的單元格0值。返回單元格0作爲來自DataGrid中所選行的字符串
這與我在示例代碼中迭代的this question類似。
private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
foreach (DataRowView row in dataGrid.Items)
{
string text = row.Row.ItemArray[0].ToString();
Debug.WriteLine(text);
}
}
點擊項目應該得到選擇。使用'dataGrid.SelectedItem作爲DataRowView'(並做一個'null'檢查!) – ASh
@ASh你的答案和waka的答案都適用。謝謝! –