0

Can i make UpDown Column at DataGrid?

I have simple DataGrid:

 <DataGrid Grid.Row="0" Grid.Column="0">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Name">  </DataGridTextColumn>

                            </DataGrid.Columns>
  </DataGrid>

And i want to make UpDown column. Can i do that?

Thank you!

P.S. i mean something like numericUpDown counter. :up: [1], down: [0].

user2545071
  • 1,408
  • 2
  • 24
  • 46

2 Answers2

1

I think you can do something like

<DataGrid>
   <DataGrid.Columns>
      <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=AttrName}" Height="25" Width="150" HorizontalAlignment="Left" VerticalAlignment="Top" />
                                <TextBlock Text="{Binding Path=AttrDisplayLabel}" Height="25" Width="Auto" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,0,0,0" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox Height="25" 
                                      ItemsSource="{Binding Source={StaticResource cvsAttributes}}"
                                      SelectedValuePath="AttributeID"
                                      IsSynchronizedWithCurrentItem="False"
                                      SelectionChanged="Selector_OnSelectionChanged"
                                      SelectedValue="{Binding Path=AttributeId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Name}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>

                                <ComboBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <VirtualizingStackPanel />
                                    </ItemsPanelTemplate>
                                </ComboBox.ItemsPanel>

                            </ComboBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
 ....

Just replace combo with your updown/spinner control. The celltemplate is your display... the celledittemplate is your edit control...(updown...etc...)

Kixoka
  • 989
  • 4
  • 15
  • 37
0

If you mean NumericUpDown column

you can have a template column and add NumericUpDown Control to the template

Look Here for creating custom numeric updown control or simply use one provided with WPFToolkit !!

Find Codeples for Toolkit Here

Community
  • 1
  • 1
Muds
  • 4,006
  • 5
  • 31
  • 53