Xceed DataGrid for WPF v7.2 Documentation
Defining Unbound Columns

Welcome to Xceed DataGrid, Editors, and 3D Views for WPF v7.2 > Xceed DataGrid for WPF > Code Snippets > Defining Unbound Columns

The following example demonstrates how to use an unbound column to display a button that, when clicked, will display an editor through which the corresponding data item can be edited.

XAML
Copy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">

  <Grid.Resources>

     <xcdg:DataGridCollectionViewSource x:Key="cvs_products"

                                        Source="{Binding Source={x:Static Application.Current}, Path=Products}" />

  </Grid.Resources>

  <xcdg:DataGridControl x:Name="OrdersGrid"

                        ItemsSource="{Binding Source={StaticResource cvs_products}}">

     <xcdg:DataGridControl.Columns>

       <xcdg:UnboundColumn FieldName="EditRowColumn"

                           Width="30"

                           MinWidth="30"

                           MaxWidth="30">

          <xcdg:UnboundColumn.CellContentTemplate>

             <DataTemplate>

                <Button Click="Button_Click"

                        Content="..." />

             </DataTemplate>

          </xcdg:UnboundColumn.CellContentTemplate>

       </xcdg:UnboundColumn>

        <xcdg:Column FieldName="Photo"

                     Visible="False" />

     </xcdg:DataGridControl.Columns>

  </xcdg:DataGridControl>

</Grid>

The following code provides the implementation of the Button_Click event. The ProductsEditorWindow derives from Window and allows the data item to be edited. The code for the ProductsEditorWindow is not provided.

VB.NET
Copy Code
Private Sub Button_Click( ByVal sender As Object, ByVal e As RoutedEventArgs )

  Dim button = TryCast( sender, Button )

  Dim cell = TryCast( buttom.GetValue( Cell.ParentCellProperty), Cell )

  Dim editor = New ProductsEditorWindow( TryCast( cell.DataContext, DataRowView ) )

  editor.ShowDialog()

End Sub 
C#
Copy Code
private void Button_Click( object sender, RoutedEventArgs e )

{

  var button = sender as Button;

  var cell = button.GetValue( Cell.ParentCellProperty ) as Cell;

  var editor = new ProductsEditorWindow( cell.DataContext as DataRowView );

  editor.ShowDialog();

}