从WPF中的DataGridView获取值 [英] Get value from DataGridView in WPF

查看:168
本文介绍了从WPF中的DataGridView获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要从WPF中的DataGridView的第一列和第三列获取值。



我的代码:



Hi,

I need to get value from first and third column of a DataGridView in WPF.

My code:

<!-- My third column is a combobox, my first is the id -->
<DataTemplate x:Key="CustomLimitationTemplate">
            <StackPanel>
                <ComboBox>
                    <ComboBoxItem>Aucune</ComboBoxItem>
                    <ComboBoxItem>Légère</ComboBoxItem>
                    <ComboBoxItem>Modérée</ComboBoxItem>
                    <ComboBoxItem>Forte</ComboBoxItem>
                    <ComboBoxItem>Totale</ComboBoxItem>
                </ComboBox>
            </StackPanel>
        </DataTemplate>

<DataGrid AutoGenerateColumns="False" VerticalAlignment="Stretch" Grid.Row="2" Name="dg1" RowDetailsVisibilityMode="Collapsed" ItemsSource="{Binding Source={StaticResource XmlData},XPath=Limits/*}">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="ID" x:Name="IdColumn" Binding="{Binding XPath=Id}" />
                    <DataGridTemplateColumn Header="Capacite" CellTemplate="{StaticResource CustomCapacityTemplate}" Width="480" />
                    <DataGridTemplateColumn Header="Limitation" x:Name="LimitationColumn" CellTemplate="{StaticResource CustomLimitationTemplate}" Width="150" />
                    <DataGridTemplateColumn Header="Aide" CellTemplate="{StaticResource CustomDetailTemplate}" Width="97" />
                </DataGrid.Columns>
            </DataGrid>





现在,我不知道for循环的代码获取我的所有行中的ID和限制。



希望你能帮助我。



感谢每次提前



Now, I don't know the code of the for loop for get the ID and "Limitation" in my all row.

Hope you can help me.

Thanks per advance

推荐答案

请参考这些文章在wpf datagrid中创建ComboBox,

1. DataGrid中的ComboBox

2. ComboBox in WPF中的DataGrid
Hi, refer these article to create ComboBox in wpf datagrid,
1. ComboBox in a DataGrid.
2. ComboBox in DataGrid in WPF.


这篇关于从WPF中的DataGridView获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆