TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ilkin Turk
NA
349
161.1k
IList convert to datatable
Jul 3 2013 10:39 AM
Hello.
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<T>(IList<T> 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.
Reply
Answers (
3
)
Switch and Enum
C# edit for number and uppercase letters