按钮,获取Click事件处理程序中的行的单元格值



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);

我不完全理解你想做什么,但这应该会有所帮助。

相关内容

最新更新