At the moment the ListView gets my data - however, I want to show the data in both columns. Right now it simply displays both column values vertically.
public void PopulateListView(DataCollection<Entity> items)
{
CompanyList1.Width = 450;
CompanyList1.Height = 100;
CompanyList1.Location = new System.Drawing.Point(10, 10);
ColumnHeader header1, header2;
header1 = new ColumnHeader();
header2 = new ColumnHeader();
header1.Text = "Company Name";
header1.TextAlign = HorizontalAlignment.Left;
header1.Width = 70;
header2.TextAlign = HorizontalAlignment.Left;
header2.Text = "Primary Role";
header2.Width = 200;
CompanyList1.Columns.Add(header1);
CompanyList1.Columns.Add(header2);
CompanyList1.View = View.Details;
foreach (Entity i in items)
{
if (i.Attributes.Contains("new_primaryroleid"))
{
EntityReference role = (EntityReference)i.Attributes["new_primaryroleid"];
CompanyList1.Items.Add(i.Attributes["name"].ToString());
CompanyList1.Items.Add(role.Name);
}
else
{
CompanyList.Items.Add(i.Attributes["name"]);
}
}
}
ginger_asp
Member
255 Points
329 Posts
How to put data in ListViewcolumns
May 25, 2012 11:28 AM|LINK
At the moment the ListView gets my data - however, I want to show the data in both columns. Right now it simply displays both column values vertically.
public void PopulateListView(DataCollection<Entity> items) { CompanyList1.Width = 450; CompanyList1.Height = 100; CompanyList1.Location = new System.Drawing.Point(10, 10); ColumnHeader header1, header2; header1 = new ColumnHeader(); header2 = new ColumnHeader(); header1.Text = "Company Name"; header1.TextAlign = HorizontalAlignment.Left; header1.Width = 70; header2.TextAlign = HorizontalAlignment.Left; header2.Text = "Primary Role"; header2.Width = 200; CompanyList1.Columns.Add(header1); CompanyList1.Columns.Add(header2); CompanyList1.View = View.Details; foreach (Entity i in items) { if (i.Attributes.Contains("new_primaryroleid")) { EntityReference role = (EntityReference)i.Attributes["new_primaryroleid"]; CompanyList1.Items.Add(i.Attributes["name"].ToString()); CompanyList1.Items.Add(role.Name); } else { CompanyList.Items.Add(i.Attributes["name"]); } } }