Tag: WPF/DataGrid

目次

参考情報

DataGridComboBoxColumn

基本

編集可能にする

共通のItemsSourceを使う

値が表示されたり消えたり妙な動作

DataGridComboBoxでElementStyleやEditingElementStyleを指定し、かつIsSynchronizedWithCurrentItem=Trueを使うと同列の他の行の表示がみだれるのでやめたほうがよいっぽい。

                <DataGridComboBoxColumn Width="*" Header="変数の型">
                    <DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding Path=Types}"/>
                            <!-- これ -->
                            <Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
                            <Setter Property="DisplayMemberPath" Value="Label"/>
                            <Setter Property="IsReadOnly" Value="True"/>
                            <Setter Property="SelectedItem" Value="{Binding Type}"/>
                        </Style>
                    </DataGridComboBoxColumn.ElementStyle>
                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding Path=Types}"/>
                            <!-- これ -->
                            <Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
                            <Setter Property="DisplayMemberPath" Value="Label"/>
                            <Setter Property="SelectedItem" Value="{Binding Type}"/>
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>
                </DataGridComboBoxColumn>

DataGridTemplateColumn

ユーザーコントロールを表示する

Validation

値入力ごとの検証

DataGridColumnので設定する。以下の例ではValidatesOnDataErrorsがTrueなのでIDataErrorInfoを使って検証される。

<DataGridTextColumn Width="100" Header="名前" Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>

行全体の検証

RowValidationRulesにValidationRuleを設定する。

<DataGrid.RowValidationRules>
   <local:RowDataInfoValidationRule ValidationStep="UpdatedValue"/>
</DataGrid.RowValidationRules>

ValidationTemplate

その他

Tips

DataGridRow、DataGridCellを検索する

トラブルシューティング

追加情報: 'DeferRefresh'は、AddNewトランザクションまたはEditItemトランザクションの実行中は許可されません。

再現方法

cell.png
error.png

解決方法


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS