I would like to know what is the correct way to properly fill a datatable I have, the question is that I must fill it with different lists where I have my information, now my datatble looks like this:
What I want is that column 2 is at the same level as my column 1.
Code C #:
List<List<string>> LstList = new List<List<string>>();
LstList.Add(lstUsing.Items.Cast<string>().ToList());
LstList.Add(lstExternal.Items.Cast<string>().ToList());
LstList.Add(lstFunctions.Items.Cast<string>().ToList());
LstList.Add(lstMe.Items.Cast<string>().ToList());
DataTable dtSim = new DataTable();
for (int i = 0; i < LstList.Count; i++)
{
dtSim.Columns.Add("Col "+(i+1));
if (i == 0) {
for (int x = 0; x < LstList.ElementAt(i).Count; x++)
{
DataRow dr = dtSim.Rows.Add();
dr.SetField("Col 1", lstUsing.Items.Cast<string>().ToList().ElementAt(x));
}
} else if (i==1) {
for (int x = 0; x < LstList.ElementAt(i).Count; x++)
{
DataRow dr = dtSim.Rows.Add();
dr.SetField("Col 2", lstExternal.Items.Cast<string>().ToList().ElementAt(x));
}
}
}