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

Manually data fill

This seems very basic, but still can't found how to do it

For X, Y or Z reasons I need to manually add rows to a DataGrid

May or may not know the number/type of columns, so, this is why I need to do it manually instead of binding

I'm using the WinRT package on a Windows Phone universal app

I was thinking on some very basic stuff, like 

_grid.Rows.Add();
_grid.Rows[row, column].Text = "Some text";

Can't dounf any on the Docs related to manually add data

10 Replies

SU sunco February 24, 2015 10:53 PM UTC

Also tried with a List of Lists with no luck

var rows = new List<List<string>>();

rows.Add(new List<string>() { "aa", "bb" });
rows.Add(new List<string>() { "cc", "dd" });

_grid.ItemsSource = rows;


MG Mohanraj Gunasekaran Syncfusion Team February 26, 2015 04:01 AM UTC

Hi Isaac,

Thank you for contacting Syncfusion support,

We have analyzed your query and you can achieve your requirement “Manually data fill” by using dynamic type column to load by the button click. Please refer the attached sample in following location.

Sample location: http://www.syncfusion.com/downloads/support/directtrac/118305/Manually_Add_the_Column-1149750162.zip

If your requirement is differ from this, please share more details regarding your request or else please modify the sample based on your requirement that would be more helpful for us to serve you better.

Please let us know if you have any other queries.

Regards,

Mohanraj.




SU sunco February 26, 2015 04:51 AM UTC

Ok, thanks for your answer

I download your code and saw it but is exactly what I want to avoid

You said is dynamic, but you have static fields (Employeeid, Employeename, Orderid, Column1)

So, that way you can tell how many columns you need and also the exact name of the columns

The app I try to do is Mysql client. So you can't tell the column names/size, so I think on a List of Lists - I mean this List<List<string>>

Is easy to add headers

_grid.Columns.Add(new GridTextColumn() { HeaderText = "field name" });

When I see on the docs you can use a List as DataSource, then I think on this:

List<List<string>> res = new List<List<string>>();

res.Add(new List<string> { "aa", "bb", "cc" });
res.Add(new List<string> { "dd", "ee", "ff" });
res.Add(new List<string> { "gg", "hh", "ii" });

_grid.ItemsSource = res;

Sorry about my bad english, I don't want to be rude, I just don't know how exactly say some stuff



MG Mohanraj Gunasekaran Syncfusion Team February 27, 2015 03:47 PM UTC

Hi Isaac,

We are sorry about the inconvenience  caused.

We have provide the solution for this query ”Manually data fill” in Incident 135831. Please check this incident for more details.

Please let us know if you have any queries.

Regards,

Mohanraj




SU sunco February 27, 2015 05:54 PM UTC

Finally I was able to complete this, thanks. Your code give me the key

I write the answer here in case somebody need it

The problem was the MappingName that I had omitted when creating the columns (didn't know was required)

_grid.Columns.Add(new GridTextColumn() { HeaderText = "field 1", MappingName = "[0]" });
_grid.Columns.Add(new GridTextColumn() { HeaderText = "field 2", MappingName = "[1]" });
_grid.Columns.Add(new GridTextColumn() { HeaderText = "field 3", MappingName = "[2]" });

List<List<string>> res = new List<List<string>>();

res.Add(new List<string> { "aa", "bb", "cc" });
res.Add(new List<string> { "dd", "ee", "ff" });
res.Add(new List<string> { "gg", "hh", "ii" });

_grid.ItemsSource = res;


MG Mohanraj Gunasekaran Syncfusion Team March 2, 2015 05:20 AM UTC

Hi Isaac,
 
Thank you for your update.
 
Please let us know if you require further assistance from us.




MN manik narang March 3, 2015 06:28 AM UTC

Can you share the code for your last changes regarding the Mapping Name, That will help me alot,
Thanks


SU sunco March 3, 2015 06:40 AM UTC

Ahm.. check my answer

The MappingName is in bold

You need to map the 'array' position


MN manik narang March 3, 2015 07:01 AM UTC

the problem is i need to extract a dynamic model out of all this
,so as the code suggests that there should be a Dynamic Type Coloumn or an ObervableCollection<dynamic> columns which will become an array(correct me if i am wrong)
hence the Mapping Name would be Column[0],Column[1]....and so on?


MK Muthukumar Kalyanasundaram Syncfusion Team March 5, 2015 06:14 PM UTC

Hi Manik,

 

Sorry for the delay in response.

 

If you want to add column dynamically in SfDataGrid, you can use “Columns.Add()” to add the column dynamically by using dynamic. We have customized the sample to add column and property at runtime using dynamic as per your need. Please refer the below code,

 

Code:

private void Button_Click(object sender, RoutedEventArgs e)

{

var colleciton = (this.syncgrid.DataContext as OrderInfoViewModel).DynamicOrders as ObservableCollection<dynamic>;

colleciton[0].Country = "USA";

this.syncgrid.Columns.Add(new GridTextColumn() { MappingName = "Country" });

}

 

Please let us know if you have any concerns.

 

Regards,

Muthukumar K


Attachment: DynamicColumns_6c3a7e01.zip

Loader.
Live Chat Icon For mobile
Up arrow icon