Using ItemsSourceBinding on a System.Data.DataRow

3 posts, 1 answers
  1. Steve
    Steve avatar
    5 posts
    Member since:
    Sep 2010

    Posted 05 Jan 2011 Link to this post

    I have a GridViewComboBoxColumn bound to a System.Data.DataRow, and I am having trouble using ItemsSourceBinding to bind the items to another column on the row. If I use ItemsSource I have no trouble - see the sample code below.

    How should I be using ItemsSourceBinding for a System.Data.DataRow data context?

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            StackPanel stackPanel = new StackPanel();
            stackPanel.Children.Add( CreateItemsSourceGridTelerik_WORKING() );
            stackPanel.Children.Add( CreateItemsSourceGridTelerik_NOTWORKING() );
            Content = stackPanel;
        }
      
        public class Node
        {
            public string Description { get; set; }
            public string Code { get; set; }
        }
      
        RadGridView CreateItemsSourceGridTelerik_WORKING()
        {
            RadGridView grid = new RadGridView { AutoGenerateColumns = false };
      
            grid.Columns.Add( new GridViewComboBoxColumn
            {
                DataMemberBinding = new Binding( "Column" ),
                DisplayMemberPath = "Description",
                SelectedValueMemberPath = "Code",
                ItemsSource = new Node[] {
                    new Node { Description = "One", Code = "1" },
                    new Node { Description = "Two", Code = "2" }
                },
            } );
      
            DataTable table = new DataTable();
            table.Columns.Add( "Column" );
      
            DataRow row = table.NewRow();
            table.Rows.Add( row );
            row[ "Column" ] = "2";
      
            grid.ItemsSource = table.DefaultView;
      
            return grid;
        }
      
        RadGridView CreateItemsSourceGridTelerik_NOTWORKING()
        {
            RadGridView grid = new RadGridView { AutoGenerateColumns = false };
      
            grid.Columns.Add( new GridViewComboBoxColumn
            {
                DataMemberBinding = new Binding( "Column" ),
                DisplayMemberPath = "Description",
                SelectedValueMemberPath = "Code",
                ItemsSourceBinding = new Binding( "ColumnItems" ),
            } );
      
            DataTable table = new DataTable();
            table.Columns.Add( "Column" );
            table.Columns.Add( "ColumnItems" );
      
            DataRow row = table.NewRow();
            table.Rows.Add( row );
            row[ "Column" ] = "2";
            row[ "ColumnItems" ] = new Node[] {
                new Node { Description = "One", Code = "1" },
                new Node { Description = "Two", Code = "2" }
            };
      
            grid.ItemsSource = table.DefaultView;
      
            return grid;
        }
    }

  2. Answer
    Maya
    Admin
    Maya avatar
    3824 posts
    Member since:
    Sep 2012

    Posted 06 Jan 2011 Link to this post

    Hi Steve,

    You need to define the type of the ColumnItems collection:

    RadGridView CreateItemsSourceGridTelerik_NOTWORKING()
    {
        DataTable table = new DataTable();
        table.Columns.Add("Column");
        table.Columns.Add("ColumnItems", typeof(Node[]));
    }


    Regards,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF

  3. Download a free trial of UI for WPF
  4. Steve
    Steve avatar
    5 posts
    Member since:
    Sep 2010

    Posted 06 Jan 2011 Link to this post

    Thanks, that works.   For an items source of an anonymous type, typeof( IEnumerable ) seems to be enough for Telerik to work with.

Back to Top