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

[Solved] RadGridView 2011 with Silverlight Lightweight Datatable

1 Answer 95 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
vedant
Top achievements
Rank 1
vedant asked on 15 Aug 2011, 04:56 PM
Hello,

 I recently start using  RadGridView for SL 4 development for POC project for sharepoint 2010. I have problem with dynamic data binding.
 Here is what I am doing, I am using light weight data table from here and my grid is created based on users requirement (if user want 3 rows grid has 3 rows) . Now example project mentioned works fine but when I assign column name on the fly as per my code below binding fails. I saw the list getting assigned to radgridview as List<Dynamicclass>()

So, Does anyone know why data binding fails in RadGridView when column names generated on the fly.

Code:
 	public MainPage()
        {
            InitializeComponent();
            Random rnd = new Random();
            DataTable table = new DataTable();

            for (int i = 0; i <= col; i++)             {                 var coln = "- " + i.ToString();                 table.Columns.Add(new DataColumn() { ColumnName = coln, DataType = typeof(string) });             }             for (var r = 0; r < row; r++)             {                 DataRow row = new DataRow();                 for (int c = 0; c <= col; c++)                 {                     var coln = "- " + c.ToString();                     row[coln] = "Hello";                 }                 table.Rows.Add(row);             }             RadGridView1.ItemsSource = table.ToList();         } } please do get data.cs and dynamic.cs files from post mentioned above it has code for light weight data table.

1 Answer, 1 is accepted

Sort by
0
vedant
Top achievements
Rank 1
answered on 15 Aug 2011, 07:28 PM
So, I finally figured it out.
ColumnName have to start with char rather than special char or Number.

Here is updated code. Notice Column Name. 

 public MainPage()
        {
            InitializeComponent();
            Random rnd = new Random();
 
            table = new DataTable();
 
            for (int i = 0; i <= 5; i++)
            {
                var coln = "col " + i.ToString();
                table.Columns.Add(new DataColumn() { ColumnName = coln, DataType = typeof(string) });
            }
 
            for (var r = 0; r < 10; r++)
            {
                DataRow row = new DataRow();
                for (int c = 0; c <= 5; c++)
                {
                    var coln = "col " + c.ToString();
                    if (c == 2)
                    {
                        row[coln] = " ";
                    }
                    else
                    {
                        row[coln] = "Hello";
                    }
                }
                table.Rows.Add(row);
            }
 
            RadGridView1.ItemsSource = table.ToList();
        }
Tags
GridView
Asked by
vedant
Top achievements
Rank 1
Answers by
vedant
Top achievements
Rank 1
Share this question
or