12 Answers, 1 is accepted
Please refer to the following article which explains how to work list Lists and RadGridView: http://docs.telerik.com/devtools/winforms/gridview/populating-with-data/binding-to-generic-lists
In addition, you may have a look at the entire section which concerns the different ways to populate RadGridView with data.
I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.
Regards,
Stefan
Telerik

Dear Stefan,
I read the online document but it is not in the case.
I would like to describe more detail: objects is Dictionary<string, object>, for ex:
row1 (Dictionary) : ID = 1, Name = ABC, Age = 20
row2 (Dictionary): ID = 2, Name = XYZ, Age = 23
.....
I try to set grid.DataSource = new List<Dictionary<string, object>>() { row1, row2, ...}. The Grid show corrected number of lines but has no column data.
How can I bind the data source in this case? (grid is in read or edit mode).
Regards,
Tuan
Thank you for writing.
If each dictionary contains only one entry there is no point to add the dictionary objects to a list. You can directly bind the grid to the dictionary. For example:
var data =
new
Dictionary<
string
, MyObj>();
for
(
int
i = 0; i < 20; i++)
{
data.Add(i.ToString(),
new
MyObj { Name =
"Name "
+ i, Age = 30 });
}
radGridView1.DataSource = data;
This way the grid will display the Key and the Value in each row (those are the properties of the dictionary entry object).
If you want to display you custom business object properties you should bind the grid to a list of objects. For example:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
var data =
new
List<MyObj>();
for
(
int
i = 0; i < 20; i++)
{
data.Add(
new
MyObj { Name =
"Name "
+ i, Age = 30 });
}
radGridView1.DataSource = data;
}
}
class
MyObj
{
public
string
Name {
get
;
set
; }
public
int
Age {
get
;
set
; }
}
If this does not help could you please share the exact way that you are initializing your data structure (use some sample data), and perhaps you can specify how exactly you expect the grid to look like.
I am looking forward to your reply.
Regards,
Dimitar
Telerik

I got your response in mailbox but it had not been in the forum.
I had tried as your sample. But i'm sorry it is not in my situation. Because my object has dynamic properties belong to each customer site, so i can't use the strong type object (as MyObj). That is the reason i used Dictionary to store the properties.
So, can i customize or extend the grid?
Regards,
Tuan
p/s: I am evaluate the Telerik control to decide replacing ObjectListView (opensource) in my project.
Can you give some sample data so I can see how it is built? Can you show me how this looks in your current control? This information will give me a better understanding of your exact requirement and I will see if this is possible with our grid.
I am looking forward to your reply.
Regards,
Dimitar
Telerik

Dear Dimitar,
I add sample code as below.
Thank for your reply.
Regards,
Tuan
------------------
private void InitializeGrid()
{
// Turn on the column auto generation, depend on return data from service.
this.radGridView1.AutoGenerateColumns = true;
// Setup grid's data. This is just simulation the return data from WebAPI service
//BindingList<Dictionary<string, object>> models = new BindingList(service.GetPersonalData())
BindingList<Dictionary<string,object>> models = new BindingList<Dictionary<string, object>>();
string[] names = new string[] { "ROOT", "Mark", "Piet", "Herre", "Ronald", "John", "Michael" };
Random rand = new Random();
for (int i = 0; i < 1000; i++)
{
Dictionary<string, object> row = new Dictionary<string, object>();
row["Id"] = i + 1;
row["Name"] = names[rand.Next(names.Length)];
row["Age"] = rand.Next(100);
row["Active"] = false;
models.Add(row);
}
// Bind return data to grid
this.radGridView1.DataSource = models;
}
Thank you for writing back.
There is no way to directly display such data in RadGridView, however, you can use RadVirtualGrid for this case. I have attached a small sample to show you how this works. More information about this control is available in the following articles:
Let me know if you have additional questions.
Regards,
Dimitar
Telerik

Thank you so much for your support.
I confirmed the sample. I will investigate the RadVirtualGrid for editing mode, performance and other features.
Regards,
Tuan
I am glad I could be of help. Let us know if you have any other questions.
Regards,
Dimitar
Telerik


Dear Sir,
Actually I have Radgrid that is bind dynamically with a Sql Database on a Serverside but now i want to change the datasource(a dictionary<key,Value> more than one key and value) at client side using jquery or javascript.
so i want to know is it possible to do this ??
and how ?can you please tell me ?
Thank you for writing.
This thread is discussing RadGridView for WinForms. In case you are using a different product and technology please post your question in the relevant forum.
Regarding the grid in WinForms please refer to the reply of my colleague above: http://www.telerik.com/forums/can-i-bind-list-of-dictionary-string-object-to-radgridview#2B2FMb14SkSb-Xkqzv6WeQ.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress