ListView

  • Thread starter Thread starter Liz
  • Start date Start date
L

Liz

How do I add columns ACROSS and lines down from an array
to a ListView.

ListView1.Update();
ListView1.Items.Clear();
ListView1.Items.Add(aClients[1].Surname);
ListView1.Items.Add(aClients[1].Forename);

**starts new line
 
How do I add columns ACROSS and lines down from an array
to a ListView.

ListView1.Update();
ListView1.Items.Clear();
ListView1.Items.Add(aClients[1].Surname);
ListView1.Items.Add(aClients[1].Forename);

**starts new line

Well, ListView1.Columns.Add whatever columns needed, then
something like this
foreach(row in array)
{
ListViewItem lItem = ListView1.Items.Add(row[0]);
for(int x = 1; x < rowcolumns)
{
lItem.SubItems.Add(row[x]);
}
}

or in this specific case

ListView1.Columns.Add(Surname);
ListView1.Columns.Add(Forename);

for(int x = 0; x < aClients.Count; x++)
{
ListViewItem lItem = ListView1.Items.Add(aClients[x].Surname);
lItem.SubItems.Add(aClients[x].Forename);
}
 
Ah - subItems - thanks very much.

Now I'm having difficulty picking up which item was
selected. The following always gives me 17????

private void ListView1_DoubleClick(object sender,
System.EventArgs e)
{
label10.Text = ListView1.TabIndex.ToString();
}

-----Original Message-----
How do I add columns ACROSS and lines down from an array
to a ListView.

ListView1.Update();
ListView1.Items.Clear();
ListView1.Items.Add(aClients[1].Surname);
ListView1.Items.Add(aClients[1].Forename);

**starts new line

Well, ListView1.Columns.Add whatever columns needed, then
something like this
foreach(row in array)
{
ListViewItem lItem = ListView1.Items.Add(row[0]);
for(int x = 1; x < rowcolumns)
{
lItem.SubItems.Add(row[x]);
}
}

or in this specific case

ListView1.Columns.Add(Surname);
ListView1.Columns.Add(Forename);

for(int x = 0; x < aClients.Count; x++)
{
ListViewItem lItem = ListView1.Items.Add(aClients [x].Surname);
lItem.SubItems.Add(aClients[x].Forename);
}
 
I would use
ListViewItem lItem = ListView1.SelectedItems[0];
label0.Text = lItem.SubItems[0] + ", " + lItem.SubItems[1];

this should set label0 to "surname, forename";
 
Back
Top