The ListView Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom

    #1

    The ListView Control

    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.Coun t = 1. Where did that "1"
    come from? Shouldn't it be "0"? It is still there after I do
    t.Clear().

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: The ListView Control

    Hi,

    "Dom" <dolivastro@gma il.comwrote in message
    news:1188488457 .024453.123430@ r29g2000hsg.goo glegroups.com.. .
    >
    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.Coun t = 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.Te xt, the second column are the SubItems.
    Not only that, but SubItems[0] is the ListViewItem.Te xt !!!
    That explain why t.SubItems.Coun t shows 1 instead of 0 as you were
    expecting.


    Comment

    • Dom

      #3
      Re: The ListView Control

      On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
      laceupsolutions .comwrote:
      Hi,
      >
      "Dom" <dolivas...@gma il.comwrote in message
      >
      news:1188488457 .024453.123430@ r29g2000hsg.goo glegroups.com.. .
      >
      >
      >
      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.Coun t = 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.Te xt, the second column are the SubItems.
      Not only that, but SubItems[0] is the ListViewItem.Te xt !!!
      That explain why t.SubItems.Coun t 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

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: The ListView Control

        Hi,

        "Dom" <dolivastro@gma il.comwrote in message
        news:1188499846 .852016.313650@ i13g2000prf.goo glegroups.com.. .
        On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
        laceupsolutions .comwrote:
        >Hi,
        >>
        >"Dom" <dolivas...@gma il.comwrote in message
        >>
        >news:118848845 7.024453.123430 @r29g2000hsg.go oglegroups.com. ..
        >>
        >>
        >>
        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.Coun t = 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.Te xt, the second column are the
        >SubItems.
        >Not only that, but SubItems[0] is the ListViewItem.Te xt !!!
        >That explain why t.SubItems.Coun t 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


        Comment

        Working...