The ListView Control

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

Still making my way through cSharp. I've started using the ListView
control, and I'm already up against the wall. My code looks something
like this:

ListViewItem t = new ListViewItem();
for (...)
{
t.SubItems.Add (...);
}
ListView1.Add (t);

The problem is that the columns of the listview are shifted to the
right by one column. After debugging around, I found that "t = new
ListViewItem();" shows that t.SubItems.Count = 1. Where did that "1"
come from? Shouldn't it be "0"? It is still there after I do
t.Clear().
 
Hi,

ListViewItem t = new ListViewItem();
for (...)
{
t.SubItems.Add (...);
}
ListView1.Add (t);

That looks fine, but how many columns do you have? I have never ever had a
need to do a for to add the subitems.

The problem is that the columns of the listview are shifted to the
right by one column. After debugging around, I found that "t = new
ListViewItem();" shows that t.SubItems.Count = 1. Where did that "1"
come from? Shouldn't it be "0"? It is still there after I do
t.Clear().

The first column is ListViewItem.Text, the second column are the SubItems.
Not only that, but SubItems[0] is the ListViewItem.Text !!!
That explain why t.SubItems.Count shows 1 instead of 0 as you were
expecting.
 
Hi,




ListViewItem t = new ListViewItem();
for (...)
{
t.SubItems.Add (...);
}
ListView1.Add (t);

That looks fine, but how many columns do you have? I have never ever had a
need to do a for to add the subitems.
The problem is that the columns of the listview are shifted to the
right by one column. After debugging around, I found that "t = new
ListViewItem();" shows that t.SubItems.Count = 1. Where did that "1"
come from? Shouldn't it be "0"? It is still there after I do
t.Clear().

The first column is ListViewItem.Text, the second column are the SubItems.
Not only that, but SubItems[0] is the ListViewItem.Text !!!
That explain why t.SubItems.Count shows 1 instead of 0 as you were
expecting.

Thanks, Ignacio. That explains it for me. For the record, I do a
"for" loop to add the subitems because I don't know how many subitems
I need before hand. The user enters an Access filename, and then
chooses to list one of the Schema for the file, eg, the tables, or the
indexes. The information you get for the table (name, creation data,
etc), is not the same as the information you get for the indexes.

But your answer is what I needed. I'm going to add an initial column
that will just count off the row number.

Thanks, again
 
Hi,

Dom said:
Hi,




ListViewItem t = new ListViewItem();
for (...)
{
t.SubItems.Add (...);
}
ListView1.Add (t);

That looks fine, but how many columns do you have? I have never ever had
a
need to do a for to add the subitems.
The problem is that the columns of the listview are shifted to the
right by one column. After debugging around, I found that "t = new
ListViewItem();" shows that t.SubItems.Count = 1. Where did that "1"
come from? Shouldn't it be "0"? It is still there after I do
t.Clear().

The first column is ListViewItem.Text, the second column are the
SubItems.
Not only that, but SubItems[0] is the ListViewItem.Text !!!
That explain why t.SubItems.Count shows 1 instead of 0 as you were
expecting.

Thanks, Ignacio. That explains it for me. For the record, I do a
"for" loop to add the subitems because I don't know how many subitems
I need before hand. The user enters an Access filename, and then
chooses to list one of the Schema for the file, eg, the tables, or the
indexes. The information you get for the table (name, creation data,
etc), is not the same as the information you get for the indexes.

But your answer is what I needed. I'm going to add an initial column
that will just count off the row number.

Ok, just remember that you need to have the same number of columns
 
Back
Top