ListView

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
 
M

Morten Wennevik

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);
}
 
L

Liz

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);
}
 
M

Morten Wennevik

I would use
ListViewItem lItem = ListView1.SelectedItems[0];
label0.Text = lItem.SubItems[0] + ", " + lItem.SubItems[1];

this should set label0 to "surname, forename";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top