public partial class Form1 : System.Windows.Forms.Form
{
public static DataTable dtData = new DataTable();
public static DataRow newRow = dtData.NewRow();
private void Form1_Load(object sender, EventArgs e)
{
Query();
BindData();
}
public static void Query()
{
dtData.Columns.Add("ID", typeof(string));
dtData.Columns.Add("at", typeof(string));
dtData.Columns.Add("cm", typeof(string));
dtData.Columns.Add("cn", typeof(string));
dtData.Columns.Add("an", typeof(string));
dtData.Columns.Add("sn", typeof(string));
dtData.Columns.Add("ce", typeof(string));
foreach (ListItem listItem in items)
{
newRow = dtData.NewRow();
newRow["ID"] = listItem["ID"];
FieldUserValue username = (FieldUserValue)listItem["at"];
string un = username.LookupValue;
newRow["at"] = un;
var cntnum = listItem["cn"] as FieldLookupValue[];
if (cntnum != null)
{
foreach (var contracts in cntnum)
{
cns = contracts.LookupValue;
}
newRow["cn"] = cns;
}
FieldLookupValue an = listItem["an"] as FieldLookupValue;
an = an.LookupValue;
newRow["an"] = an;
var sysname = listItem["sn"] as FieldLookupValue[];
if (sysname != null)
{
foreach (var system in sysname)
{
sn = system.LookupValue;
}
newRow["sn"] = sn;
}
//Capturing contact email(s)
var email = listItem["ce"];
newRow["ce"] = email;
}
//trying to bind ->
bs.DataSource = dtData;
}
public void BindData()
{
txtcn.DataBindings.Add("Text", bs, "cn");
txtan.DataBindings.Add("Text", bs, "an");
txtsn.DataBindings.Add("Text", bs, "sn");
txtce.DataBindings.Add("Text", bs, "ce");
}