This is a migrated thread and some comments may be shown as answers.

Using ItemsSourceBinding on a System.Data.DataRow

2 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 05 Jan 2011, 11:26 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 06 Jan 2011, 05:16 PM
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
0
Steve
Top achievements
Rank 1
answered on 06 Jan 2011, 09:21 PM
Thanks, that works.   For an items source of an anonymous type, typeof( IEnumerable ) seems to be enough for Telerik to work with.
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Maya
Telerik team
Steve
Top achievements
Rank 1
Share this question
or