I need to convert Ilist to datatable using below method.But couldnt.Please help .
Here when I select items from checkbox of ultracomboeditor - I need to add them to datatable.So
this.ultraComboEditor1.CheckedListSettings.CheckBoxStyle = CheckStyle.CheckBox;
System.Collections.IList values = null;
values = this.ultraComboEditor1.Value as System.Collections.IList;
my Problem is to convert the ILIst to datatable.
using below method I want to convert IList to datatable.Please show how.
public DataTable ToDataTables(IList data)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for (int i = 0; i < props.Count;i++ )
{
PropertyDescriptor prp = props[i];
table.Columns.Add(prp.Name,prp.PropertyType);
}
object[] values = new object[props.Count];
foreach(T item in data)
{
for (int i = 0; i < values.Length;i++ )
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}
Thanks in advance.
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 3, 2013, 11:53 AM
The output is:
I'm not familiar with the UltraComboEditor but I've been looking at the docs for it and, from what you say, it sounds like it's the CheckedItems property you want to convert to a DataTable.
Now the type of this property is CheckedValueListItemsCollectionand, as far as I can see, it doesn't implement either IList or its generic equivalent.
Posted Jul 3, 2013, 11:35 PM
Jignesh TrivediPosted Jul 3, 2013, 11:22 PM
Please check following link it might help you.
http://stackoverflow.com/questions/564366/convert-generic-list-enumerable-to-datatable
http://www.dotnetperls.com/convert-list-datatable