Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to have only one column with buttons

Sort Posts: Previous Next
  •  06-17-2009, 1:28 PM Post no. 21757

    How to have only one column with buttons

    I have a DataGridControl which is bound to an Observable collection. This is working fine and I see my generated columns and the cells are filled in just fine.
    Problem:
    Now I want to add an additional column whose sole purpose is to have cells that are themselves buttons or contain buttons so that the user can click the button and do something that deals with that row the button is on.
    I tried (1) adding a Column with a CellContentTemplate and a Button. On button click, however, I was unable to know which row I was on which is key in order for me to do something dealing with that row. Leaving out some details:

    This is try (1)

    <Grid x:Name ="ItemsGrid">

        <xcdg:DataGridControl Name="MyDataGridControl"

             ...........

             ItemsSource="{Binding Path=MyObservableCollection,....

                <xcdg:DataGridControl.Columns>

                    <xcdg:Column FieldName="AdditionalButtonColumn" Title="Perform Action">

                        <xcdg:Column.CellContentTemplate>

                            <DataTemplate>

                                <Button Content="Get Data" Click="GetDataButton_Click".....

                            </DataTemplate>

                        </xcdg:Column.CellContentTemplate>

                    </xcdg:Column>

                </xcdg:DataGridControl.Columns>

            </xcdg:DataGridControl>

    </Grid>


    I also tried (2) using a style and a ControlTemplate for the DataCells that will display the cells as buttons. I found how to do this in the Xceed Templates documentation. But this applies a style to all my cells for all my columns and I only want one column to have the cells as buttons.

    This is try (2)

    <Grid x:Name ="ItemsGrid">

        <Grid.Resources>

            <Style TargetType="{x:Type xcdg:DataCell}">

                <EventSetter Event="MouseDown" Handler="GetData_MouseDown_Handler"/>

                <Setter Property="Template">

                    <Setter.Value>

                        <ControlTemplate TargetType="{x:Type xcdg:DataCell}">

                            <Button>

                                <Button.Content>

                                    <ContentPresenter/>

                                </Button.Content>

                            </Button>

                        </ControlTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </Grid.Resources>

        <xcdg:DataGridControl Name="MyDataGridControl"

             ...........

             ItemsSource="{Binding Path=MyObservableCollection,....

                <xcdg:DataGridControl.Columns>

                    <xcdg:Column FieldName="AdditionalButtonColumn" Title="Perform Action">

                    </xcdg:Column>

                </xcdg:DataGridControl.Columns>

            </xcdg:DataGridControl>

    </Grid>


     

  •  06-17-2009, 4:45 PM Post no. 21764 in reply to 21757

    Re: How to have only one column with buttons

    Hi Flor,

    I would recommend using the new Unbound Column. The example provided should point you in the right direction.
    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Unbound_Columns.html

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  07-02-2009, 9:27 AM Post no. 22216 in reply to 21757

    Re: How to have only one column with buttons

    I found out this can also be done through the use of a DataTemplate of a button and then customizing your columns by setting AutoCreateColumns="False" and setting the column's CellContentTemplate to the button DataTemplate

    <DataTemplate x:Key="ButtonTemplate">

        <Button x:Name="MyButton" Content="{Binding}" Click="GetButtonClick"</Button>

    </DataTemplate>

     

     

        <DataGrid:Column FieldName="Status" Title="Status" CellContentTemplate="{StaticResource ButtonTemplate}"/>

     

    In this example the Button itself is bound to the property the Column is bound to.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.