xml:我的数据网格中的按钮
<DataGridTemplateColumn Header="Update">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Update" Name="btnEmpGridUpdate" Tag="{Binding Path = EMPID}" Click="btnEmpGridUpdate_Click" ></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
按钮事件中的代码:
Object Id = new Object();
Id = ((Button)sender).Tag;
这是检索选定行的所有单元格值的可能方法吗?如果,我该怎么做?否则,请建议我使用其他方法从数据网格更新我的数据集。提前致谢 。 :)
最佳答案
使用这些辅助函数; http://techiethings.blogspot.com/2010/05/get-wpf-datagrid-row-and-cell.html
在您的更新按钮上,连接 Click 事件,并在处理程序中执行如下操作:
//youll need to google for GetVisualParent function.
DataGridRow row = GetVisualParent<DataGridRow>(button);
for(int j = 0; j < dataGrid.Columns.Count; j++)
DataGridCell cell = GetCell(dataGrid, row, j);
我不完全明白你想做什么,但这应该有所帮助。
关于c# - DataGrid 列中的按钮,获取它来自 Click 事件处理程序的行的单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11601198/