如何在WPF中的GridC的SelectionChanged事件上获取所选的行值

时间:2016-04-20 15:19:13

标签: wpf

            

            <DataGridTextColumn Header="ProductID" Width="70" Binding="{Binding ProductId}"></DataGridTextColumn>
            <DataGridTextColumn Header="Product Name" Width="100" Binding="{Binding ProductName}"></DataGridTextColumn>
            <DataGridTextColumn Header="MeasurementId" Width="100" Binding="{Binding MesurementID}"></DataGridTextColumn>
            <DataGridTextColumn Header="Price" Width="75" Binding="{Binding Price}"></DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

我的事件:private void Grid1_SelectionChanged(object sender,SelectionChangedEventArgs e)         {} 如果我在任何一行中选择如何获取所有列值..请帮助我

2 个答案:

答案 0 :(得分:1)

查看SelectionChangedEventArgs。它有AddedItems属性,其中包含所选项目。

答案 1 :(得分:0)

您可以使用它来检索在

中触发的DataGridRow组合框
private void ComboBoxRight_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ComboBox comboBox    = (ComboBox) sender;
        DataGridRow row      = (DataGridRow) dataGrid.ContainerFromElement(comboBox);
        int rowIndex         = row.GetIndex();
        YourModel gridModel    = (YourModel) dataGrid.Items[rowIndex];
    }