Lightweight DataTable for your Silverlight applications

Thursday, April 23, 2009 by Vladimir Enchev | Comments 113

 

UPDATE: Please visit this post for more info about dynamic objects binding!

 

Since there is no DataTable in Silverlight I’ve created small class that can be used to generate columns and rows in runtime in similar to the real DataTable way:

DataTable table = new DataTable();

table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) });
table.Columns.Add(new DataColumn() { ColumnName = "UnitPrice", DataType = typeof(decimal) });
table.Columns.Add(new DataColumn() { ColumnName = "Date", DataType = typeof(DateTime) });
table.Columns.Add(new DataColumn() { ColumnName = "Discontinued", DataType = typeof(bool) });

for(var i = 0; i < 1000; i++)
{
DataRow row = new DataRow();
row["ID"] = i;
row["Name"] = names[rnd.Next(9)];
row["UnitPrice"] = prizes[rnd.Next(9)];
row["Date"] = DateTime.Now.AddDays(i);
row["Discontinued"] = bools[rnd.Next(9)];

table.Rows.Add(row);
}

 

Enjoy!

113 Comments

  • Ben Hayat 23 Apr
    Vlad, thank you very much. This is very helpful to create a large client table for testing;
    ..Ben
  • Frenk 24 Apr
    Wonderful!
    Little question: how can I create a column with custom object as DataType?

    I have a class similar to this that contains additional information on the value I want to display (I then bind to these things with the cellTemplate):

    public class MyValue 
        public string DisplayValue { getset; } 
        public double InternalValue { getset; } 
        public Brush DisplayColor { getset; } 
        // ... other metadata on my value 


    However if I create a column of type MyValue I get an exception (No applicable indexer exists in type 'KeyValuePair`2').
    But if I create the column with DataType object then I cannot do sorting and grouping.
  • Vlad 24 Apr
    Hi Frenk,

    You can use your own types however you will need to set typeof(object) for the DataColumn. Example:

    DataTable table = new DataTable();

    table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
    table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) });
    table.Columns.Add(new DataColumn() { ColumnName = "UnitPrice", DataType = typeof(decimal) });
    table.Columns.Add(new DataColumn() { ColumnName = "Date", DataType = typeof(DateTime) });
    table.Columns.Add(new DataColumn() { ColumnName = "Discontinued", DataType = typeof(bool) });
    table.Columns.Add(new DataColumn() { ColumnName = "MyObject", DataType = typeof(object) });

    for (var i = 0; i < 1000; i++)
    {
        DataRow row = new DataRow();
        row["ID"] = i;
        row["Name"] = names[rnd.Next(names.Length)];
        row["UnitPrice"] = prizes[rnd.Next(names.Length)];
        row["Date"] = DateTime.Now.AddDays(i);
        row["Discontinued"] = bools[rnd.Next(names.Length)];
        row["MyObject"] = new MyObject();

        table.Rows.Add(row);
    }

    Vlad
  • Chris 26 Apr
    I tried this sample, but when pressing the insert key to create a new record, once I hit enter an error is thrown and I get a white page.

    Does this method allow new data to be added to the datatable?

     

    private void RadGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)

     

    {

     

     

    DataRow row = new DataRow();

     

    row[

     

    "ID"] = table.Rows.Count;

     

    row[

     

    "Name"] = string.Empty;

     

    row[

     

    "UnitPrice"] = 0;

     

    row[

     

    "Date"] = DateTime.Now;

     

    row[

     

    "Discontinued"] = false;

     

    e.NewObject = row;

    table.Rows.Add(row);

     

     

    //RadGridView1.Rebind();

     

     

    }

    I tried the Rebind() as well and got the following error:

    Specified cast is not valid
       at lambda_method(ExecutionScope , DataRow )
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Telerik.Windows.Data.RecordTreeBuilder`1.GetListFromEnumerable(IEnumerable data)
       at Telerik.Windows.Data.RecordTreeBuilder`1.Initialize(IEnumerable data, IList`1 groupings, IList`1 sorts, IRecordFactory newRecordFactory)
       at Telerik.Windows.Data.RecordManager.ResetRecords()
       at Telerik.Windows.Controls.DataControl.Rebind()
       at SilverlightDataTable.Page.RadGridView1_AddingNewDataItem(Object sender, GridViewAddingNewEventArgs e)
       at Telerik.Windows.Controls.RadGridView.OnAddingNewDataItem(GridViewAddingNewEventArgs e)
       at Telerik.Windows.Controls.GridView.GridViewItemsControl.CreateNewDataItem()
       at Telerik.Windows.Controls.GridView.GridViewItemsControl.ShowAddNewRow()
       at Telerik.Windows.Controls.GridView.GridViewNewRow.BeginEdit()
       at Telerik.Windows.Controls.GridView.GridViewItemsControl.HandleKeyDownEvent(KeyEventArgs e)
       at Telerik.Windows.Controls.GridView.GridViewItemsControl.OnKeyDown(KeyEventArgs e)
       at System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

    Thanks

    Chris
  • Vlad 27 Apr
    Hi Chris,

    Here is a small addition for the DataTable class:
    ...
            public object NewRow()
            {
                if (queryable != null)
                {
                    return Activator.CreateInstance(queryable.ElementType);
                }

                return null;
            }
    ...

    You can use this method for e.NewObject:

            void RadGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
            {
                DataRow row = new DataRow();

                e.NewObject = table.NewRow();

                table.Rows.Add(row);
            }
  • Chris 27 Apr
    Hi Vlad,

    Thanks for the response.

    In terms of "queryable", it's not defined.  Should this be a property?

    Regards,

    Chris
  • Silverwhopper 27 Apr

    Vlad,

    Thanks, the DataTable works great, I have a few questions though.

    Here is the snippet below, it has a few issues:

    Problem 1. For the objBusinessData, when I debug, I get "Could not evaluate expression" (probably since its generated with the Emit calls inside the Dynamic.cs. How can I get to the properties of the currently selected object in the gridview. I build a DataTable with data coming from a WCF service call.

    Problem 2. The approach I take below works only when table is not sorted, when I sort by clicking on a column header the rows gets reordered and I get other row data. The "table" object was populated initially after the service call when I retrieved the data from the service. This results in showing the image for another row.

    question: How can we use the DataTable with the grid in edit mode, teoretically, TwoWay binding should persist the changes to the DataTable in memory. Later I want to call a service with a list of changes and that service routine will ultimately make the changes to the database

     

    1         private void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)  
    2         {  
    3             try 
    4             {  
    5                 if (this.RadGridView1.SelectedRecords.Count == 1)  
    6                 {  
    7                     object objBusinessData = RadGridView1.SelectedItem;  
    8  
    9                     //!!!!!!!!hack!!!!!!!!!  
    10                     int nrecIndex = ((Telerik.Windows.Data.DataRecord)(RadGridView1.SelectedRecord)).DataSourceIndex;  
    11                     DataRow dtRow = table.Rows[nrecIndex];  
    12                     string sValue = (string)dtRow["file_data"];  
    13                     string sAssetTag = (string)dtRow["asset_tag"];  
    14                     byte[] fileBytes = Convert.FromBase64String(sValue);  
    15  
    16                     MemoryStream ms = new MemoryStream(fileBytes);  
    17                     BitmapImage image = new BitmapImage();  
    18                     ms.Position = 0;  
    19                     image.SetSource(ms);  
    20                     myImage.Source = image;  
    21                 }  
    22             }  
    23             catch (Exception)  
    24             {  
    25  
    26             }  
    27         } 

    Thanks,

     

  • silverwhopper 27 Apr
    Vlad,
     I re-post the lign of code that got cut:

    Line10:      int nrecIndex = ((Telerik.Windows.Data.DataRecord)(RadGridView1.SelectedRecord)).DataSourceIndex;
  • Vlad 28 Apr
    Hi Silverwhopper,

    You can get DynamicClass properties using reflection:

    if (this.RadGridView1.SelectedRecords.Count == 1) 

        object objBusinessData = RadGridView1.SelectedItem; 
         PropertyInfo[] props = objBusinessData.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

        string sValue = (string)props.Where(pi=>pi.Name == "file_data").FirstOrDefault().GetValue(objBusinessData, null);
        string sAssetTag = (string)props.Where(pi=>pi.Name == "asset_tag").FirstOrDefault().GetValue(objBusinessData, null);

        byte[] fileBytes = Convert.FromBase64String(sValue);

        MemoryStream ms = new MemoryStream(fileBytes);
        BitmapImage image = new BitmapImage();
        ms.Position = 0;
        image.SetSource(ms);
        myImage.Source = image;
    }

    Other possible approach can be found here:
    http://blogs.telerik.com/stefandobrev/posts/09-02-16/transpose_or_just_rows_as_columns.aspx

    Vlad
  • Chris 28 Apr
    Hi Vlad,

    I'm not sure if my post is being missed due to another post, so I thought I'd post again.

    First, thank you for your previous response.  It's greatly appreciated.

    I added the NewRow method to the DataTable but "queryable" is not defined.  Should it be as follows?

     

    IQueryable queryable = rows.AsQueryable();

     

     

    This seems to work, however, when I add a new record, and move through the fields, when I hit enter I get

    "Unhandled Error in Silverlight 2 Application Code: 4004
    Category: ManagedRuntimeError
    Message: System.InvalidCastException: Unable to cast object of type "Telerik.Data.DataRow' to type 'DynamicClass1'.

    I'm not sure what queryable should be...I suspect some type of DynamicClass object.

    Thanks in advance.

    Regards,

    Chris

     

  • Vlad 29 Apr
    Hi Chris

    Sorry for the confusion! Here is the new code:
            public object NewRow()
            {
                if (queryable != null)
                {
                    return Activator.CreateInstance(queryable.ElementType);
                }

                return null;
            }

            #region IEnumerable Members

            IQueryable queryable = null;
            public IEnumerator GetEnumerator()
            {
                if (queryable == null)
                {
                    var entries = new List<string>();
                    int i = 0;

                    foreach (DataColumn column in Columns)
                    {
                        string name = String.IsNullOrEmpty(column.ColumnName)?
                            String.Format("Column{0}", i) : column.ColumnName;

                        entries.Add(String.Format(@"{1}(it[""{0}""]) as {0}",
                            column.ColumnName, column.DataType.Name));
                       
                        i++;
                    }

                    var projection = String.Format("new ({0})",
                        String.Join(",", entries.ToArray()));

                    queryable = Rows.AsQueryable().Select(projection);
                }

                return queryable.GetEnumerator();
            }

            #endregion


    Vlad
  • Chris 29 Apr
    Thank you Vlad...that worked great.

    I appreciate all your help.

    Sincerely,

    Chris
  • Chris 05 May
    Hi Vlad,

    I made one of the columns invisible and then on the BeginningEdit event, tried to check it's value.  The Cell for this invisible column does not appear.  It appears that the e.Row.DataContext should be used. 

    When checking the e.Row.DataContext I get the error "Could not evaluate expression".  This works fine when bound to an ObservableCollection.

    I really like the idea of the datatable for generic quick data retrieval and binding.  Does the observable collection have a property that handles this that is required in the datatable?

    Thank you again in advance.

    Regards,

    Chris

  • Richard Clark 06 May
    Hi Vlad

    Thanks for the post , do you have a VB version of the Dynamic.cs for silverlight ? i have tried to translate but have had little joy

    Regards,

    Richard C
  • Vlad 07 May
    Hi Chris,
    Here is an alternative approach how to get values:

    void RadGridView1_BeginningEdit(object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e)
    {
       int id = (int)e.Row.DataContext.GetType().GetProperty("ID").GetValue(e.Row.DataContext, null);
    }


    Hi Richard,

    You can find VB version of Dynamic LINQ here:
    http://msdn.microsoft.com/en-us/bb964686.aspx

    You will need to comment (or remove) ReaderWriterLock related code since cannot be compiled in Silverlight.

    Vlad

  • sam 22 May
    Hi Vlad,

    We are evaludating the Grid View and we are planning to buy the Silverlight control. After the datatable are filled with data that load from database, (using your example to create a datatable), an error occured after we  bind dataGrid.ItemsSource to a a DataTable.  It only occurs if there is null value in our data. How we going to handle it?

    We will have image, text, datetime, double, boolean datatype in our columns.

    thank you for  your help?

    sam

    "   at lambda_method(ExecutionScope , DataRow )\r\n   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n   at Telerik.Windows.Data.ListBindingHelper.GetFirstItemByEnumerable(IEnumerable enumerable)\r\n   at Telerik.Windows.Data.ListBindingHelper.GetPropertiesFromFirstItem(IEnumerable enumerable)\r\n   at Telerik.Windows.Data.ListBindingHelper.GetListItemPropertiesByEnumerable(IEnumerable enumerable)\r\n   at Telerik.Windows.Data.ListBindingHelper.GetListItemProperties(Object list)\r\n   at Telerik.Windows.Data.TableDefinition.InitializeDefinitionData(Object newDataSource)\r\n   at Telerik.Windows.Data.TableDefinition.ReinitializeDefinitionData(Object newDataSource)\r\n   at Telerik.Windows.Data.TableDefinition.OnDataSourceChanged(EventArgs e)\r\n   at Telerik.Windows.Data.TableDefinition.set_DataSource(Object value)\r\n   at Telerik.Windows.Controls.GridView.GridViewDataControl.ChangeItemsSource()\r\n   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClassd.<Bind>b__c()\r\n   at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)\r\n   at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)\r\n   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)\r\n   at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)\r\n   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)\r\n   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)\r\n   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)\r\n   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\r\n   at Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)\r\n   at Gerber.WebFolio.Client.Views.Style.StyleGridView.client_GetDesignCompletedHandler(DesignHeaderDTO design)\r\n   at Gerber.WebFolio.Client.ServiceClient._designServiceClient_GetDesignCompleted(Object sender, GetDesignCompletedEventArgs e)\r\n   at Gerber.WebFolio.ServiceProxy.ProxyDesignService.DesignServiceClient.OnGetDesignCompleted(Object state)"
  • Vlad 25 May
    Hi sam,

    I've made some changes in my DataTable class and you can check the new version along with small example here:
    http://blogs.telerik.com/Libraries/Vladimir_Enchev/SilverlightDataTable_2009_0525.sflb?download=true

    Let me know how it goes.

    Vlad
  • sa 26 May
    Thanks Vlad,

    If I have a hard coded DataType, such as 
    table.Columns.Add(new DataColumn() { ColumnName = "Date", DataType = typeof(DateTime?)});
    It works fine without any problems.
     
    But our datatype is get from a string such as

    var dc = new DataColumn
                                 {
                                     ColumnName = db.ColumnName,
                                     DataType = Type.GetType(db.DataType)
                                 };

    Here "db.DataType" is a Full name of type, i.e "System.DateTime", how can I change it to accept null value?

    Thanks
  • Vlad 26 May
    Hi,

    Here is an example:

    table.Columns.Add(new DataColumn() { ColumnName = "UnitPrice", DataType = typeof(Nullable<>).MakeGenericType(Type.GetType("System.Decimal")) });


    Vlad
  • Thomas Lebrun 07 Jul
    Hi Vlad,

    Do you have any ideas on how I could implement to send, from a WCF service, a DataTable object to my Silverlight application ?

    I would like to construct the table on the server and send it to the client but it does not work: DataRow must have the DataContract attribute but it tnherit from Dictionary so it implements the ISerialisable and it's not possible to use both.

    I've managed to use the following class for DataRow:

    public

     

    class DataRow : IEnumerable
    {

     

    [

    DataMember]

     

     

    public Dictionary<string, object> Data { get; set; }

     

     

    public DataRow()

     

    :

    base()

     

    {

    Data =

    new Dictionary<string, object>();

     

    }

     

    public object this[string key]

     

    {

     

    get

     

    {

     

    return Data[key];

     

    }

     

    set

     

    {

    Data[key] =

    value;

     

    }

    }

     

    }


    XML is correclty sent from the server but Silverlight is not able to parse/deserialize it and nothing is retrieve.... :(


    Any ideas ?


    Thanks !


    Thomas.
  • Lakshmi 13 Jul
    Hi Vlad,

    Could you please post the vb version of Data.CS?

    Thanks!

    Lakshmi
  • Vlad 14 Jul
    Hi Thomas,

    If you can send us (via support ticket) small demo project demonstrating your case I will gladly help you.

    Hi Lakshmi,

    You can convert Data.cs to VB.NET very easily (I've just tried) using our powerful converter
  • Eyad 20 Aug
    Hi Vlad,
    Great work. Thanks for the post.

    However, could you please provide a code to know how to populate it, as we do in the normal data table using ADO.Net.
    Really, am working on a scenario where am sending the table name to the service method and then the required ( to return data within this table). I couldn't achieve this using LINQ since I have lots of dynamic tables that I don't and can't add them all to dbml. So I need a solution as yours, to be able to fill data table by any data and use it in my silverlight app.
    Ex:

    MyServiceMethod(string tbl)
    {
    SqlConnection con = new SqlConnection(ConString);
    SqlCommand cmd = new SqlCommand("select * from " + tbl,con);

    SqlDataAdapter da = new SqlDataAdapter;

    Now I need to fill your data table and the return it back to silverlight where I called this service mehtod.
    }

    Could you please guide me ? And we are using your components.

    Thank you in advance.

    Best Regards,
    Eyad

  • Eyad 31 Aug
    Hi Vlad,

    Please I've used your code and I've added a checkbox column to the grid. I want to change some cells values when Checking a box.

    I've did this within OnCheckBoxChecked :

    private void OnCheckBoxCheckedUnchecked(object sender, RoutedEventArgs e)
            {
     GridViewRow row = ((CheckBox)sender).ParentOfType<GridViewRow>();

    row.DataContext.GetType().GetProperty("Name").SetValue(row.DataContext,"New Value",null);
           }
    The data is changed here, but nothing happened in the grid ?
  • Denisse 03 Sep
    Hi,

    I am using your datatable and I am having trouble to update the columns of the gridview that is binded to the dataTable. I wasn't able to update rows either, until I did this:

    Grid.ItemsSource = null;
    Grid.ItemsSource = myDataTable;

    However, when I add columns dynamically to the dataTable and reasign it as itemssource to the gridview, the new columns aren't displayed.

    How can I solve this?

    Thank you


  • Vlad 03 Sep
    Hi Eyad,

    Sorry for the late reply!

    I'm not sure if you can serialize my DataTable from the server - you will get problems most probably due to dynamic types however you can return from your service standard DataTable as string and parse this on the Silverlight client using XDocument to my DataTable. Here is an example:

    server-side:
    public string GetData()
            {
                DataTable table = new DataTable(); // this is standard DataTable
                table.TableName = "MyTable";
                table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
                table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) });


                for (var i = 0; i < 10; i++)
                {
                    DataRow row = table.NewRow();
                    row["ID"] = i;
                    row["Name"] = String.Format("Name{0}", i);

                    table.Rows.Add(row);
                }

                StringWriter writer = new StringWriter();
                table.WriteXml(writer);

                return writer.ToString();
            }

    client-side:
    void client_GetDataCompleted(object sender, SilverlightApplication.ServiceReference1.GetDataCompletedEventArgs e)
            {
                var doc = XDocument.Parse(e.Result);

                var table = new DataTable();

                table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
                table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) });

                foreach(var item in doc.Descendants("MyTable"))
                {
                    DataRow row = new DataRow();

                    row["ID"] = int.Parse(item.Descendants("ID").First().Value);
                    row["Name"] = item.Descendants("Name").First().Value;

                    table.Rows.Add(row);
                }

                RadGridView1.ItemsSource = table;
            }

    Can you try to call Rebind() to see what will be the result for your second question?

    Hope this helps!

    Vlad

  • Vlad 03 Sep
    Hi Denisse,

    Unfortunately I'm not sure what is causing this and the only option I can suggest you is to send me small example project via support where this issue can be demonstrated. I will review your scenario and I will get back to you with more info.

    Vlad
  • Bill 09 Sep
    Hi,Vlad,
       I'm using your latest version of DataTable, but I still get that "System.InvalidCastException ... at lambda_method ..." error. It works fine if the columns are all of string type, but if there's a column of type other than that, the exception will be thrown.

       Could you try this and provide a more real-life example of using that datatable?

     Thanks,

    Bill  
  • Vlad 09 Sep
    Hi Bill,

    I've just updated my blog post and you can download the new version of my DataTable with support for custom types.

    Vlad
  • Bas 23 Sep
    Hi Vlad,

    Can you provide a small example for add and remove of a row to the DataTable in your example.
    if I add a new row to the DataTable or remove a row from the DataTable.Rows collection after the initial binding to the grid and rebind the grid I only see the initial content of the DataTable.

    Thanks,

    Bas
  • Vlad 23 Sep
    Hi Bas,

    I've made small additional method for the data table which will help you to handle such cases easily:

                public IList ToList() 
            { 
                var enumerator = GetEnumerator(); 
                var list = (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(queryable.ElementType)); 
                while (enumerator.MoveNext()) 
                { 
                    list.Add(enumerator.Current); 
                } 
                return list; 
            } 

    Just bind the grid to this list and everything should work as expected:
    ...
     RadGridView1.ItemsSource = table.ToList();
    ...

    Vlad
  • Bas 23 Sep

    Hi Vlad,

    Thanks, that fixes my problem!
    The code from your post on 27 Apr 2009 does not work because the Rows collection in the DataTable is only used once because queryable != null when you rebind to the datatable.

    void RadGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
    {
    DataRow row = new DataRow();
    e.NewObject = table.NewRow();
    table.Rows.Add(row);
    }

    Instead of the code above you can use this code with the additional method from your previous post:

    void radGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
    {
    var newItem = dataTable.NewRow();
    e.NewObject = newItem;
    ((sender as RadGridView).ItemsSource as IList).Add(newItem);
    }


    Bas
  • JohnMo 06 Oct
    Thanks for building this Vlad.  I noticed if the column name is a numeric string, the datatable doesn't work as an itemssource.  I have years as columns so this example fails.  Is there an easy solution to this problem? 

     var table = new DataTable();

                table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
                table.Columns.Add(new DataColumn() { ColumnName = "2007", DataType = typeof(string) });

                foreach(var item in doc.Descendants("MyTable"))
                {
                    DataRow row = new DataRow();

                    row["ID"] = int.Parse(item.Descendants("ID").First().Value);
                    row["Name"] = item.Descendants("2007").First().Value;

                    table.Rows.Add(row);
                }

                RadGridView1.ItemsSource = table;
  • JohnMo 06 Oct
    update to above:  the row["Name"] row should read

    row[

    "2007"] = Convert.ToDecimal(2.2).ToString();

     



    changing the row's column name to "test" will work but "2007" will not.
  • Deven 09 Oct
    Excellent solution. You made it so easy.
  • Deven 09 Oct
    Hello Vlad,
    Thanks for providing such a powerful solution. I have one minor issue.

    Since I am just displaying data everything works just fine. However, if I use a space or parenthesis in the Column name, I get Parse error  "{')' or ',' expected". Is there anyway we can allow column names to have spaces or parenthesis?

    Thanks
    Deven
  • Patrick 10 Oct
    Deven,

    I believe the DataTable column names have to follow the naming requirements for identifiers. One hack is to just do a simple string replace on the column name when you add the column. E.g., given that you have a string array of column names with spaces in them:

    foreach (string name in _colNames) {  
       table.Columns.Add(new DataColumn() {   
          ColumnName = name.Replace(@" ", @"_"), DataType = typeof(bool) });  
       } 

    After adding your rows and setting the gridview itemsource, you can do the opposite operation on the gridview column headers themselves to turn the underscores back into spaces. Ugly but works.

    hth,
    Patrick

  • Patrick 10 Oct
    Vlad, this is really neat and helps me out for a proof-of-concept thing I need to demo in a couple of days. Thanks!

    Patrick
  • Park 14 Oct
    Hi Vlad

    I am testing on telerik GridView for silverlight . And i managed to bind  data from web service
    by your datatable. I appeciated it . But I couldn't sort , filter , group , moving colums when i bound
    datatable in GridView I found  out all GridViewColumn's properties(eg  IsSortable , IsFilterble) are set to false . 
    I don't know how to solve this problem .   Please Help me to solve this problem 
  • Park 14 Oct
    Hi Vlad

    I am testing on telerik GridView for silverlight . And i managed to bind  data from web service
    by your datatable. I appeciated it . But I couldn't sort , filter , group , moving colums when i bound
    datatable in GridView I found  out all GridViewColumn's properties(eg  IsSortable , IsFilterble) are set to false . 
    I don't know how to solve this problem .   Please Help me to solve this problem 
  • Vlad 15 Oct
    Hi Park,

    Can you check DataType for these columns? If the type is not sortable, filterable and groupable the grid will set these column properties to false.

    Vlad
  • Park 15 Oct
    Vlad

    I changed datatable library from your datatable to silverlight dataset library. (you can find sourcecodes
    here http://silverlightdataset.net/silverlightdataset/Default.aspx )  

    It works fine in doing filtering , grouping , sorting. But I can't apply custom filter row  I don't know 
    why  there aren't no Cell instances in Cells Collection when Custom filter row's initialized  method is called. 

    (IEnumerable<GridViewHeaderCell> cells = row.Cells.OfType<GridViewHeaderCell>(); )

    In Addition, Is it possible to change default filter not to show "select All" in filter context Menu.
    It take a long time to select all data when there are a lot of data in GridView and a lot of column's data
    Categories. So Web browser looks like freezed. 

    I am going to use telerik silverlight control on my next project. So I should solve this problem ASAP 
    I can't use any ORM like solution because i should use legacy SQL server 's stored procedure 

    I am not native english speaker So Please Let me know If you don't understand what i meant

    Park  
     

               

  • Park 16 Oct
    Vlad

    I checked DataType. And i forgot to assign datatype of data. after i assignd proper type it works fine 
    I encounter another error when  colum name starts with numeric value? (like 2009-10-15) 
    I think it's comes from  dynamic linq method .because of c# language limitation which valiable name
    can't starts with numeric letter. But I am not sure why error comes
    I am a newbie in .net world . Can I be supported by telerik team on web even if i didn't purchase
    product?  I am working on trial version on these days.

    Park.
  • GS 09 Nov
    Urgent!!!

    Vlad,
    I've built my GridView's items source that bind to the light weight Datatable, that was downloaded from here. It works perfectly in read mode.

    However, If I edit data in cell. The changed value just shows in UI, but not in ItemsSource. The items source still has old data.

    Is this possible because the light weight datatable doesnot implement INotificatinChanged? How to implement it ? could you please provide codes for that ? thanks a lot.

    GS
  • GS 10 Nov
    Vlad,

    following my last comment, how to make the Datatable binding to GridView Editable? Right now, The UI value are editable but the ItemsSource never updated. As soon as you click column header to sort, all the value restore back.

    Thanks
    GS
  • Vlad 13 Nov
    Hi GS,

    You can use posted ToList() method to convert the enumerable to list and set ItemsSource and everything will work as expected.
    I've updated also the download link to use the most recent version.

    Vlad
  • AH 14 Nov
    Urgent!!!

    I posted ToList() method to convert the enumerable to list and set ItemsSource to maky user edit datat in ui bu The datatable still has old data. why
    Please Help
    Thanks
    AH
  • AH 14 Nov
    Urgent!!!

    I posted ToList() method to convert the enumerable to list and set ItemsSource to maky user edit datat in ui bu The datatable still has old data. why
    Please Help
    Thanks
    AH
  • AH 14 Nov
    Urgent!!!

    I posted ToList() method to convert the enumerable to list and set ItemsSource to maky user edit datat in ui bu The datatable still has old data. why
    Please Help
    Thanks
    AH
  • AH 14 Nov
    Urgent!!!

    I posted ToList() method to convert the enumerable to list and set ItemsSource to maky user edit datat in ui bu The datatable still has old data. why
    Please Help
    Thanks
    AH
  • Vlad 16 Nov
    Hello AH,

    You can check the attached project where everything works as expected. Do you have latest grid version (Q3)?

    Vlad
  • july.ant 19 Nov
    Hello Vladimir,

    Thanks for your example, it is very helpful for my needs. But I also need to apply column formatting. How can I do it using your DataTable? Column count and properties are built at run time, so I cann't format them in the designer.

    Thanks in advance
    Juliana

  • Patrick 19 Nov
    I seem to be having the same issue as GS and AH. I am using Q3 version of the controls.

    Doing this:

    radGridView.ItemsSource = dataTable.ToList();

    If I set a breakpoint and inspect the DataTable in both the CellEditEnded and RowEditEnded methods, I can see that nothing has changed in the table.

    I reviewed the sample project linked to on 16 Nov, but I don't see anything relating to this question.

    Doubtless there will be other cases where you will want to do something with changes made by a user to the datagrid, like persist them to a database. So where and how does one access those changes?

    Thanks!
  • Vlad 04 Dec
    Hi Juliana,

    There is no problem to use your own declared columns instead auto-generated column since the dynamically generated type will have DataTable column names as public properties. For example:

    <telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" AutoExpandGroups="True"
        <telerik:RadGridView.Columns> 
            <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}"
                 
            </telerik:GridViewDataColumn> 
        </telerik:RadGridView.Columns> 
    </telerik:RadGridView> 

    You can use this approach to apply conditional formatting.

    Hi Patrick,

    When you call ToList() actually you will create completely new object (generic list) not related to the original table in any way. To find changes you can use grid Items property instead or just expose your own IList variable and assign to this variable the result from table.ToList(). Later you can iterate this list items (or directly grid.Items). You can try this code in CellEditEnded for example:

    private void RadGridView1_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e) 
        var uniqueName = e.Cell.Column.UniqueName; 
        var item = e.Cell.DataContext; 
        MessageBox.Show(item.GetType().GetProperty(uniqueName).GetValue(item, null).ToString()); 

    Vlad
  • Tiago 04 Dec

    Hi, My name is Tiago, I am a french guy, so sorry for my english.

    With the DataTable, I would like to know, how I can return an object stored in a row. I would like access to the methods and attribut of this one.

    Regards, Tiago

  • Tiago 04 Dec

    Hi, My name is Tiago, I am a french guy, so sorry for my english.

    With the DataTable, I would like to know, how I can return an object stored in a row. I would like access to the methods and attribut of this one.

    Regards, Tiago

  • Vlad 07 Dec
    Hi Tiago,

    You can use the approach from my last comment - Items property of the grid + reflection:

    foreach(var item in RadGridView1.Items)
    {
         var yourPropertyNameValue =  item.GetType().GetProperty(YourPropertyName).GetValue(item, null);
    }

    Vlad
  • Julien 18 Jan
    Hi Vlad,

    Thanks for your work.

    I manage to retrieve the SelectedItem property
    (

    myGrid.Items(Position).GetType.GetProperty(FieldName).GetValue(grd_Main.Items(Position),

    Nothing).ToString()

     

     

     

    )

    otherwise, i
    do not know how to retrieve the SelectedItem property.

    Can you help me please

    Thanks
  • Julien 18 Jan
    Hi Vlad,

    Thanks for your work.

    I manage to retrieve the SelectedItem property
    (

    myGrid.Items(Position).GetType.GetProperty(FieldName).GetValue(grd_Main.Items(Position),

    Nothing).ToString()

     

     

     

    )

    otherwise, i
    do not know how to retrieve the SelectedItem property.

    Can you help me please

    Thanks
  • Julien 18 Jan
    Sorry, i'm find, it's easy...

     

    For Each item In myGrid.SelectedItems

     

     

    Dim test = item.GetType().GetProperty(FieldName).GetValue(item, Nothing)

     

     

    Next

     

  • Julien 18 Jan
    Sorry, i'm find, it's easy...

     

    For Each item In myGrid.SelectedItems

     

     

    Dim test = item.GetType().GetProperty(FieldName).GetValue(item, Nothing)

     

     

    Next

     

  • Surender 06 Mar
    Hi,

    This is great work. 

    I would lie to use Lightweight DataTable along with the example provided by your collegue about gridviewextendedcolumnexample
    on post "http://www.telerik.com/community/forums/silverlight/gridview/editing-gridviewdatacolumn-cell.aspx#1114922".

    I would like to dynamically generate RadGridView and at the same type in certain scenario(optionally), I would like on certain column to have custom EditorType on each cell.

    How can I integrate your Example with one provided in "http://www.telerik.com/community/forums/silverlight/gridview/editing-gridviewdatacolumn-cell.aspx#1114922" by Nedyalko Nikolov.

    Regards,
    Surender.
  • Surender 06 Mar
    Hi,

    This is great work. 

    I would lie to use Lightweight DataTable along with the example provided by your collegue about gridviewextendedcolumnexample
    on post "http://www.telerik.com/community/forums/silverlight/gridview/editing-gridviewdatacolumn-cell.aspx#1114922".

    I would like to dynamically generate RadGridView and at the same type in certain scenario(optionally), I would like on certain column to have custom EditorType on each cell.

    How can I integrate your Example with one provided in "http://www.telerik.com/community/forums/silverlight/gridview/editing-gridviewdatacolumn-cell.aspx#1114922" by Nedyalko Nikolov.

    Regards,
    Surender.
  • Surender 08 Mar
    How do I add a Combobox to one of the columns of the dynamically generated RadGridView?

    Could you post an example code snippet, please

    Regards.
  • Vlad 08 Mar
    Hi  Surender,

    You can catch AutoGeneratingColumn event and set e.Column to desired column (even your custom column) to replace any auto-generated column. You can also add more columns using Column.Add() method.

    Vlad
  • Surender 12 Mar
    Hi Vlad,

    Thanks for your suggestion. I was able to successfully attach combobox using AutoGeneratingColumn event. I will try out the editor type next.

    I have one more question based on your blog

    http://blogs.telerik.com/vladimirenchev/posts/10-01-22/how_to_serialize_your_datatable_to_silverlight_using_wcf_service.aspx

    I want to send some more properties of "data schema" from WCF to Silverlight using something like you have mentioned....

    [OperationContract]
    public IEnumerable<Dictionary<string, object>> GetData()
    {
        var table = YourDataTable;
    
        var columns = table.Columns.Cast<DataColumn>();
    
        return table.AsEnumerable().Select(r => columns.Select(c =>
                             new { Column = c.ColumnName, Value = r[c] })
                         .ToDictionary(i => i.Column, i => i.Value != DBNull.Value ? i.Value : null));
    }
    
    The additional properties I would like to have in DataColumn class are 
    1. ColumnSize  
    2. NumericPrecision
    3. NumericScale and use these properties for data validation. How can I send these properties from WCF and use these properties for validation (for example "Customer Name" Cannot be more than 30 Characters) while building the Class dynamically? I appreciate your help on this. Regards, Surender.
  • Vlad 12 Mar
    Hi Surender,

    Generally this code can handle serialization of standard DataTable/DataColumn only. For any other custom objects you may need to use standard WCF approach with custom objects. On the client side you can create your own wrapper / view-model with these additional properties to handle your scenario.

    Vlad
  • Surender 15 Mar
    Hi Vlad.

    Thanks for pointing on what can be serialized. 
    I have one more question. After modifying the data in the grid.

    How do I send it back to WCF  from Silverlight, so that it can update the Database?

    I am trying to use similar to what you have done (WCF - > Silverlight), using
    public IEnumerable<Dictionary<string, object>> GetData()
    {
    
    Is it possible to use
    public IEnumerable<Dictionary<string, object>> SendData()
    {
    .....
    ....
    
    
     return table.AsEnumerable().Select(r => columns.Select(c =>
                             new { Column = c.ColumnName, Value = r[c] })
                         .ToDictionary(i => i.Column, i => i.Value != DBNull.Value ? i.Value : null));
    }
    

    Thanks in advance for you help.

    Regards.



  • Mike 14 Apr

    Hi Vlad,

    Class DataTable : INotifyCollectionChanged, IEnumerable

    But changing cell value in GridView, I can't fall into  void OnRowsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)

    Binding TwoMode.

    Thanks,

    Mike

  • Mike 14 Apr

    Hi Vlad,

    Class DataTable : INotifyCollectionChanged, IEnumerable

    But changing cell value in GridView, I can't fall into  void OnRowsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)

    Binding TwoMode.

    Thanks,

    Mike

  • Mike 14 Apr

    Intresting: Row value is changing. But I can't take action type.

    Help me, please.

    Regards,

    Mike

  • Igor 16 Apr

    Hello Vladimir,

    Is it possible to binding DataTable with other components like TextBox, NumericUpDown, Label... through DataContext or something else?

    Regards,

    Igor

  • Vlad 20 Apr
    Hi Igor,

    It should be no problem to bind other controls since the table will create dynamically normal INotifyCollectionChanged collection of INotifyPropertyChanged objects.

    Vlad
  • Varsha Motwani 31 May
    Hi,

    I am creating the grid Dynamically using lightweight DataTable given by Vladmir.
    I have to implement Bulk add Functionality.Can you please tell me how do I add multiple rows in Grid and show all newly added rows in Edit form.If I add one row I can show like

    this

     

     

    .radgridview.BeginInsert();
    But I want to show multiple rows.

    Please advice

     

     

  • Varsha 31 May
    HI,
    To show multiple  rows in edit format is not possible.
    Can you please just let me know how do i add multiple Blank rows to dt and get the same in data grid.
  • Vlad 01 Jun
    Hi,

    Please check the project (Button_Click event handler) to know more how to add items. I've just tried and everything worked perfectly fine! Editing multiple cells in RadGridView is not supported in general since the grid behaves very similar to MS Excel.

    Vlad
  • Kurt 24 Jun
    Solved my problem. Brilliant! Thanks a lot, I owe you beer.
  • thks 23 Jul
    can it used without telerik ?

    just with silverlight without additionnal?
  • thks 23 Jul
    just to complete my comment :

    is it used withoud telerik? ( i ask this about the datatable creation,  no  for the datagridview en the sort, just fo the data creation to put it in a simple datagrid
    in this sample, is telerik just used for designe and datagrid more completed ?

    thanks you
  • bob 23 Jul


    can we use your 6 classes (datatable and dynamic) free ?
  • Vlad 26 Jul
    Hi bob,

    Indeed you can use these for free :)

    Vlad
  • Vaji 23 Aug
    Good stuff. saved me a lot of time.
  • Dragana 24 Nov
    Hi,
    I have some problems with your classes.
    In your DynamicObjectBuilder class, reference using Telerik.Windows.Data.Dynamic; is reporting error (missing namespace).
    If I delete this and build my project, created DataTable is not valid (has some error data) and RadGridView is not updated when I assign it as ItemSource.
    Do you maybe have an idea why this is happening?

    Every help/tip is appreciated. Thanks. :)

    btw I am using trial version of your newest RadControls (RadControls for Silverlight Q3 2010).
  • Anil Lakhani 17 Dec

    Hi,

    I tried your both Data Table Versions, And found that in Old version we can not give Data Column Name with Space i.e. "Item Name", which is possible in New Version i.e. in Q3-2009 sp2 Data Table.

    But in new version, I am not able to add a column once I added rows, to that table. Which was possible in Old Version.

    My Requirement is that when I am populating Data Table, I am not aware that how many columns will need. So on every row insert I am checking that if column exists then updating row for that column else adding a new column and then updating row for that column.

    And other thing is that in my application, I also wants to allow user to add a column (i.e. Formula Column, by using existing columns)

    So please will you suggest me best approach?

    Thanks & Regards

    Anil Lakhani

  • vinay 14 Jan
    Hi

    I'm using the latest version of the DataTable (Q3-2009 sp2). Facing a problem. I have some columns where the data is integer or float. Also have some 'string' type columns. After binding, the text columns show up fine. But int and float columns dont show data. The data exists in the DataTable. On debugging, the DataGridViewColumn in radgrid has correct 'DataMemberBinding' for the text columns, but for the int and float columns, the 'DataMemberBinding' is null. On clicking on the filter icon on the grid for the int or float columns, the drop down shows the correct data to filter. But the grid itself is not showing the data - surely because of the null 'DataMemberBinding'.

    Why is the binding null for these columns. The values are not null. I have tried setting the column data type to int or string. In both cases it does not work. Any suggestions would be welcome.

    regards
    Vinay
  • vinay 14 Jan
    Hi

    found the problem - w.r.t issue above. I have column names such as 
    Weight (kg)
    Comm. Code
    Trade (USD)

    These were not working as column names. Space works but parentheses and other special chars do not. I need to set different column names.

    regards
    Vinay
  • GK 02 Mar
    Hi Vlad,

    Did you resolve Denise issue. With the current ver when I change columns colletion(add/remove) the view does not get updated. Note I am binded to radgridview.

    Simple just create a data table add items. bind to grid and show. Now add another button, in that button action add or remove columns. You will not see the grid updating.

    Any help?
  • Andrew 09 Mar
    Is it really the only way to bind dynamic data to a Telerik grid? We work with massive amounts of data (could be thousands of columns) which often changes at runtime (columns are added/deleted, tables are pivoted, etc) so creating a brand new type whenever table structure changes doesn't sound like a really good idea.

    Are there any alternatives? What happened to the good old ITypedList, just wondering if you have an internal interface similar to that one? I've heard a lot of good things about Telerik and decided to give it a try, but this is a deal-breaker for us.

    Anyone knows of other Silverlight grids that truly support that kind of dynamic data source?

    Thanks!
  • LP 09 Mar
    Can you cast this datatable to a radgridview itemsource somehow?
  • Andrew 09 Mar
    LP - you just assign it to ItemsSource property:
    radGrid.ItemsSource = myDataTable;
    
  • LP 11 Mar
    Does it work for you?  when I tried it I got a message similar to " the datatable is not compatible with telerik controls radgridview (don't remember well but it was like that).  Anyway, not a big deal.  It would be nice but if it's not possible I'll figure out something else.
  • LP 11 Mar

    can somebody please tell me what is wrong with this code? I'm trying to populate the datatable of this article but I am not able to add rows. 

    Private

     

     

    Function AddDataRow(ByRef theTable As DataTable, ByVal TheHeaders As List(Of String), ByVal TheRow As List(Of String)) As Boolean

     

     

     

    Dim success As Boolean

     

     

     

    Try

     

     

     

        Dim row As DataRow = theTable.NewRow()

     

     

     

        Dim n As Integer = 0

     

     

     

        For Each Str As String In TheRow

     

            row(TheHeaders(n)) = TheRow(n)       <-----FAILS HERE
            n = n + 1

     

     

        Next

     

        theTable.Rows.Add(row)

        success =

     

    True

     

     

     

    Catch ex As Exception
        success = False
        Return success
    End Try

     

     

     

    Return success

     

     

     

    End Function

     

  • LP 11 Mar
    Same here:

    Dim

     

     

    PTable As Telerik.Data.DataTable = New Telerik.Data.DataTable

     

     

     

     

    Dim pcolumn As DataColumn = New DataColumn

     

    pcolumn.ColumnName =

     

    "ProjectManager"

     

    pcolumn.DataType =

     

    Type.GetType("String")

     

    PTable.Columns.Add(pcolumn)

    pcolumn =

     

    New DataColumn

     

    pcolumn.ColumnName =

     

    "ProjectID"

     

    pcolumn.DataType =

     

    Type.GetType("String")

     

    PTable.Columns.Add(pcolumn)

    pcolumn =

     

    New DataColumn

     

    pcolumn.ColumnName =

     

    "TOTAL"

     

    pcolumn.DataType =

     

    Type.GetType("String")

     

    PTable.Columns.Add(pcolumn)

     

     

    Dim theRow As DataRow = PTable.NewRow()

     

    theRow.Item(

     

    "ProjectManager") = "Tim Buck Tu"  <------ Fails Here

     

    theRow.Item(

     

    "ProjectID") = "PROJ11111"

     

    theRow.Item(

     

    "TOTAL") = "500000"

     

    PTable.Rows.Add(theRow)

    Any sugestions? 

  • LP 14 Mar
    Never mind... I figured out. 
  • Andre Carlucci 21 Mar
    Hi Vladimir,

    Great job with DataTable.
    I'm having one issue though: when the column header has hyphen, no data is shown for that column.
    Any thoughts?

    Thanks in advance,

    André Carlucci
  • Vlad 21 Mar
    Hi Andre,

    Unfortunately you cannot have column name with blanks - the table will attempt to create dynamic class with such property name. You can use the grid AutoGeneratingColumn event for example to change the column Header property to desired or declare columns manually. 

    Vlad
  • Lori 31 Mar
    Hi Vlad,

    Can you help me understand how I handle drag and drop functions when using the datatable as the itemssource for a radgridview?  In particular, prior to using this, I was able to verify the drop destination as a particular textbox within a cell in the grid before allowing the drop.  Now the drop destination is consistently the dynamicobject and I'm not sure how to use this information to validation the drop destination.

    Do I need to somehow change the datatemplates used in the auto generated columns?


    Thanks.
  • Lori 01 Apr
    Never mind about the drag/drop functions.  I figured it out with a combination of previous posts in this blog as well as some in the drag/drop forums.  Thanks.
  • houston 01 Apr
    Hi Vlad,

    I would like to have a datacolumn with datatype as object. For this columni will be populating three datatypes : 
    1.string
    2.checkbox
    3.string[]

    based on the data it i need to have textblock , checkbox or combo box on my telerik radgridview.Is this possible. Any pointers are greatly appreciated.


    Thanks & Regards,
    Keerti Somasundaram
  • Igor Macedo 05 May
    Hello Vlad,

    Congratulations about this class, it's a nice job!

    There's anyway to create a new row with an array? Example:

    1 var columnData = value.Split(new[] { Separator }, StringSplitOptions.None); 
    2  
    3 table.Rows.Add(row); 

    Thanks in advance.
  • Zenigata 18 Jul
    Hi, I have download the zip code "SilverlightDataTable_2009_1109.zip".
    When I edited a cell into radgridview  I get a white page.
    Could you hel me please?
    Thanks in advance.
  • Zenigata 19 Jul
    After created a datatable and bind to gridview, if I try to add a column I receice this error:
    Read-only collection
    there is a way to do this?
    thanks in advance
  • Richard 21 Jul
    Is there a more complete sample project I can have that allows adding and editing items for example?  I can't follow these notes in practice and am very confused.
  • nite 08 Sep
    I have used your object but now I have no idea had to cast the selected item back to a row.  No matter what I do it blows up.
    var x = (CAST TO WHAT) radGridViewSelectedItem;
    Nothing works.  it is type DynamicObject but I need to get it back to a row.  Any ideas?
  • nite 08 Sep
    I have used your object but now I have no idea had to cast the selected item back to a row.  No matter what I do it blows up.
    var x = (CAST TO WHAT) radGridViewSelectedItem;
    Nothing works.  it is type DynamicObject but I need to get it back to a row.  Any ideas?
  • nite 08 Sep
    Sorry about the double post, I clicked refresh and it re-posted.
  • Jaime Bula 20 Sep
  • Vlad 21 Sep
  • nite 23 Sep
    How to you access the data once in the grid?
  • Igor 11 Nov
    How you can implement you DataTable in Hierarchical Grid?
  • jfk 17 Nov
    Having trouble converting the CreateInternalView method of the datatable class to vb.net. Code converter output does not work. Here is the original method:
            private void CreateInternalView()  
            {  
                this.internalView = (IList)Activator.CreateInstance(typeof(ObservableCollection<>).MakeGenericType(this.ElementType));  
                ((INotifyCollectionChanged)internalView).CollectionChanged += (s, e) => { this.OnCollectionChanged(e); };  
            } 

    Anyone?
    Thanks!
  • jfk 17 Nov
    JohnMo did you ever get a resolution to your issue? I am having the same problem, column names are years and the data does not get pulled in.
  • Minal 22 Dec
    Is there a way to make the dynamically generated column read-only?

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)