Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: Datagrid with Sublist

$
0
0
Hi,

A column needs to have a type. If the enumerable property has the same type for each entries, it should work :
<Window x:Class="WpfApplication46.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
        xmlns:local="clr-namespace:WpfApplication46"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525">
   <Window.Resources>
      <ObjectDataProvider x:Key="TheEnumData"
                          MethodName="GetValues"
                          ObjectType="{x:Type sys:Enum}">
         <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:TheEnum" />
         </ObjectDataProvider.MethodParameters>
      </ObjectDataProvider>
      
      <xcdg:CellEditor x:Key="enumEditor">
         <xcdg:CellEditor.EditTemplate>
            <DataTemplate>
               <ComboBox BorderThickness="0"
                         MinHeight="22"
                         VerticalContentAlignment="Top"
                         ItemsSource="{Binding Source={StaticResource TheEnumData}}"
                         SelectedValue="{xcdg:CellEditorBinding}"
                         FocusVisualStyle="{x:Null}">
               </ComboBox>
            </DataTemplate>
         </xcdg:CellEditor.EditTemplate>
      </xcdg:CellEditor>
   </Window.Resources>
    
   <Grid>
      <xcdg:DataGridControl x:Name="_dataGrid">
         <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="MyName" />
            <xcdg:Column FieldName="MyEnum"
                         CellEditor="{StaticResource enumEditor}"/>
         </xcdg:DataGridControl.Columns>
      </xcdg:DataGridControl>
   </Grid>
</Window>
namespace WpfApplication46
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();

      _dataGrid.ItemsSource = new List<MyData>()
      {
        new MyData() { MyName = "First", MyEnum = TheEnum.Blue },
        new MyData() { MyName = "Second", MyEnum = TheEnum.Blue },
        new MyData() { MyName = "Third", MyEnum = TheEnum.Green },
        new MyData() { MyName = "Fourth", MyEnum = TheEnum.Red },
        new MyData() { MyName = "Fifth", MyEnum = TheEnum.Red },
      };
    }
  }

  public enum TheEnum
  {
    Red, 
    Green, 
    Blue
  }

  public class MyData
  {
    public string MyName
    {
      get;
      set;
    }

    public TheEnum MyEnum
    {
      get;
      set;
    }
  }
}

Viewing all articles
Browse latest Browse all 2157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>