Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NumericUpDown in Datagrid

I have a WPF window that holds a bunch of numbers. Or to use nicer words: Each column is bound to one int property. Now I want to have a nice way to change some of the numbers and I was hoping that I can use a numericUpDown control. Any hints would be appreciated!

like image 944
Jan Avatar asked Feb 18 '23 13:02

Jan


1 Answers

You can use DataGridTemplateColumn.

Sample code:

<DataGrid ItemsSource="{Binding MyData}" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Name" Binding="{Binding Name}" />
                    <DataGridTemplateColumn Header="Age">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <wpfToolkit:IntegerUpDown Value="{Binding Age, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>

Where wpfToolkit is:

xmlns:wpfToolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=WPFToolkit.Extended"

In this example I use IntegerUpDown control from Extended WPF Toolkit.

like image 192
kmatyaszek Avatar answered Feb 27 '23 18:02

kmatyaszek