如何使用C#遍历datagrid行combox

时间:2019-07-02 12:04:28

标签: c# wpf data-binding datagrid wpf-controls

我对WPF并不陌生,有一个项目,其中有一个数据网格,其中有列,而数据网格行定义为绑定到项目源的组合框。我需要能够遍历所有组合框选择。在XAML中,我将组合框定义为Dcombo,但是我不知道如何动态地遍历所有创建的行。我希望获得有关如何访问它的C#代码的帮助!

<Grid Name="CGrid" Margin="25,25,31,86" Grid.ColumnSpan="1" Width="392" Height="550" Grid.Column="1" >
            <DataGrid Name="CData" Grid.Column="1" RowHeaderWidth="0" AutoGenerateColumns="False" ColumnWidth="100" EnableColumnVirtualization="False" CanUserReorderColumns="False" HorizontalScrollBarVisibility="Disabled" SelectionChanged="ClassifyData_SelectionChanged" CanUserAddRows="False" Grid.RowSpan="2" Margin="0,0,0,0">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Name" Binding="{Binding Id}"/>
                    <!--<DataGridTextColumn Header="blah" Binding="{Binding blah}"/>-->
                    <DataGridTemplateColumn Header="Thumbnail" TextBlock.TextAlignment="Center" Width="*" CanUserResize="False" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding thumbnail}" Height="150" Width="140"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                </DataGrid.Columns>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <Setter Property="DetailsVisibility" Value="Visible"/>
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.RowDetailsTemplate>
                    <DataTemplate>

                        <ComboBox Name="Dcombo" ItemsSource="{Binding combodata, Mode=TwoWay}" IsEnabled="True" SelectedIndex="0" IsSynchronizedWithCurrentItem="False" SelectedItem="{Binding combodata, UpdateSourceTrigger=PropertyChanged}"  />
                    </DataTemplate>

                </DataGrid.RowDetailsTemplate>

            </DataGrid>
        </Grid>

0 个答案:

没有答案