We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

dynamic OrderInfos.cs

Hi, 

I read your sample for SfDataGrid and I would like to know how create a dynamic DataModel (OrderInfos.cs). Or how create a DataGrid when the number of columns is variable. 



I'm new in C# and Xamarin.. :/

Thank's :) 

9 Replies

PK Prasanth Karthikeyan Syncfusion Team December 23, 2015 09:16 AM UTC

Hi Rosemond Jordan,

Thank you for using Syncfusion Products.

We have analyzed your requirement. Currently there is no support for “Dynamic Binding” in SfDataGrid. However we have already considered this requirement as a feature and currently working on it. This feature will be available in our Volume 4, 2015 main release which is scheduled to be released by the second week of January, 2016. 

Regarding your query, how create a DataGrid when the number of columns is variable?
In SfDataGrid, you can add or remove columns in runtime by simply adding or removing the column in the SfDataGrid.Columns collection.The DataGrid will automatically reflect these changes in the view. 

Please refer the below code example for adding columns at runtime.




//Sample.xaml.cs     

private void AddColumnButton_Click(object sender, EventArgs e)
{
    
this.viewModel.AddNewColumn(dataGrid);
}


// ViewModel.cs

internal void AddNewColumn(SfDataGrid sfGrid)
{
    order.AddColumn(sfGrid);

}


// OrderInfoRepository.cs

internal void AddColumn(SfDataGrid  sfGrid)
{
        
var column = new GridTextColumn() { MappingName = "StudentRegno", HeaderText ="NewColumn" };

        sfGrid.Columns.Insert(0,column);  
}


We have prepared a sample based on this and you can download the same from the below location.

Sample link: http://www.syncfusion.com/downloads/support/forum/121512/ze/SampleDemo-1172877556 

Please let us know if you have any query.

Regards,
Prasanth



RJ Rosemond Jordan December 23, 2015 03:46 PM UTC

Thank's ! :) 


PK Prasanth Karthikeyan Syncfusion Team December 24, 2015 05:18 AM UTC

Hi Rosemond Jordan,

We are glad that your issue has been fixed.

Please let us know if you require any other assistance.

Regards,
Prasanth



RJ Rosemond Jordan December 28, 2015 02:41 PM UTC

Hi, 
It's possible to bind SfDataGrid.ItemSource with a Dictionary<string, List<string>>.Where key will be the HeaderText of the column and the values will be the bindingcontext ? 

The number of item's dictionary will be variable.. 




PK Prasanth Karthikeyan Syncfusion Team December 29, 2015 05:34 PM UTC

Hi Rosemond Jordan,

We have analyzed your query. When you bind an IEnumerable<T> collection to the SfDataGrid, the items in the enumerator are the rows of type T and the properties of the each item of type T are the columns. But when you bind a Dictionary<string, List<string>> to a SfDataGrid, then the enumerator of the dictionary contains the generic object KeyValuePair<TKey,TValue> which contains only two properties: Key and Value. So the SfDataGrid will create only two columns Key and Value.

Instead you can use the dynamic object for which currently there is no support. However it will be available in our Volume 4, 2015 main release.

Please let us know if you have any query.

Regards,
Prasanth



RJ Rosemond Jordan December 30, 2015 06:58 AM UTC

Hi, 
Thank you for your answer :) 


PK Prasanth Karthikeyan Syncfusion Team December 31, 2015 08:58 AM UTC

Hi Rosemond,

Thanks for the update.

Please let us know if you require any further assistance on this.

Regards,
Prasanth



DE Dervout April 21, 2016 07:35 AM UTC

Hi,

I download the free trial for test chart and data grid. 

I don't have an object to bind with data grid. The build of the grid must be dynamic because the source is not known. I just have a list of column and a list of row. You said that the dynamic binding be available on January. How it work ? I don't see anything in the documentation.

Thanks,

Camille


VP Vimal Prabhu Manohkaran Syncfusion Team April 21, 2016 05:18 PM UTC

Hi Camille,


Currently there is no support for Dynamic Binding in Xamarin.Forms. It is a limitation of the Xamarin product without a JIT. Hence SfDataGrid for Xamarin.Forms too cannot support Dynamic Binding. For more details regarding this, please refer the below Bugzilla link.

Bug Link: https://bugzilla.xamarin.com/show_bug.cgi?id=37071


However, SfDataGrid for Xamarin.Android supports dynamic binding and please let us know if you require any details on it.


Regards,

Vimal Prabhu

Loader.
Live Chat Icon For mobile
Up arrow icon