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

DataGrid cannot use DataView as ItemsSource in 16299

1 Answer 67 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
SkyBlue
Top achievements
Rank 1
SkyBlue asked on 27 Nov 2017, 01:49 AM

I created a 16299 UWP project and use DataView as DataGrid's ItemsSource, but the UI cannot show any data.

More information, please check my code sample:

<my:RadDataGrid  x:Name="dataGrid" AutoGenerateColumns="False" >
 </my:RadDataGrid>
public sealed partial class MainPage : Page
    {
        private ObservableCollection<Dictionary<string, string>> items = new ObservableCollection<Dictionary<string, string>>();
 
        public ObservableCollection<Dictionary<string, string>> ItemDictionary
        {
            get
            {
                return items;
            }
            set
            {
                items = value;
            }
        }
 
        public DataTable Items { get; set; }
        public MainPage()
        {
            this.InitializeComponent();
            CreateItems();
            CreateTable();
        }
 
        private void CreateItems()
        {
            for (int i = 0; i < 5; i++)
            {
                Dictionary<string, string> row = new Dictionary<string, string>();
                row["A"] = "A" + i.ToString();
                row["B"] = "B" + i.ToString();
                row["C"] = "C" + i.ToString();
 
                ItemDictionary.Add(row);
 
            }
        }
 
        private void CreateTable()
        {
            Items = new DataTable();
 
            if (ItemDictionary.Count == 0) return;
 
            foreach (KeyValuePair<string, string> entry in ItemDictionary[0])
            {
                DataColumn column = new DataColumn(entry.Key);
                Items.Columns.Add(column);
                Telerik.UI.Xaml.Controls.Grid.DataGridTextColumn dgc = new Telerik.UI.Xaml.Controls.Grid.DataGridTextColumn();
                dgc.Name = entry.Key;
                dgc.Header = entry.Key;
                dgc.PropertyName = entry.Key;
                dataGrid.Columns.Add(dgc);
            }
 
            foreach (Dictionary<string, string> rowEntry in ItemDictionary)
            {
                DataRow row = Items.NewRow();
                int col = 0;
                foreach (KeyValuePair<string, string> entry in rowEntry)
                {
                    row[entry.Key] = entry.Value;
                }
                Items.Rows.Add(row);
            }
            DataView dv = Items.DefaultView;
            dataGrid.ItemsSource = dv;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 27 Nov 2017, 04:06 PM
Hi Mo,

Please see my answer to your other identical forum post here.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataGrid
Asked by
SkyBlue
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or