title: Items and Subitems in List-View control
body: <p>I'm want to use a <code>List-View</code> control to display results of an LDAP search in a "grid". I've written some test code to see how it works, but it's not being displayed as I want. As I understand it, each <code>Item</code> is equivalent to a "row" (using <code>LVS_REPORT</code>style), and the <code>Subitem</code> is equivalent to a "column" (e.g. for each item I can display a number of subitems, each in a separate column on the same row).</p>
  
  <p>Here's my test code, currently set to create four columns, with a single Item and four Subitems (corresponding to the four columns). Two functions: one to create the columns, the other to insert items.</p>
  
  <pre><code>int CreateColumns(HWND *hwndlistbox)
  {
      wchar_t *cnames[100];
      LVCOLUMN lvc;
      int i;
  
      cnames[0] = L"column1";
      cnames[1] = L"column2";
      cnames[2] = L"column3";
      cnames[3] = L"column4";
      cnames[4] = NULL;
  
      lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  
      for (i = 0; cnames[i] != NULL; i++)
      {
          lvc.iSubItem = i;
          lvc.pszText = cnames[i];
          lvc.cx = 100;
          lvc.fmt = LVCFMT_LEFT;
  
          ListView_InsertColumn(*hwndlistbox, i, &amp;lvc);
      }
  
      return i;
  }
  
  void InsertItems(HWND *hwndlistbox, int *columncount)
  {
      LVITEM lvi;
      wchar_t *items[100];
      int i, j;
  
      items[0] = L"text1";
      items[1] = L"text2";
      items[2] = L"text3";
      items[3] = L"text4";
      items[4] = NULL;
  
      lvi.mask = LVIF_TEXT;
      lvi.iItem = 0;
  
      for (i = 0; i &lt; *columncount; i++)
      {
          lvi.pszText = items[i];
          lvi.iSubItem = i;
          ListView_InsertItem(*hwndlistbox, &amp;lvi);
      }
  }
  </code></pre>
  
  <p>I expect this to generate a single row (<code>lvi.iItem = 0;</code>) with a text string under each column (<code>lvi.iSubItem = i;</code>). This is what it displays instead:</p>
  
  <p><img src="https://i.stack.imgur.com/LkPLZ.png" alt="enter image description here"></p>
  
  <p>Changing <code>lvi.iSubItem = i</code> to <code>lvi.iSubItem = 0</code> results in each text string being displayed as a new row in the first column:</p>
  
  <p><img src="https://i.stack.imgur.com/QKBll.png" alt="enter image description here"></p>
  
  <p>I've played around with it, hardcoding the numbers on both <code>iItem</code> and <code>iSubItem</code>, changing both to <code>i</code>, but I can't get it to display the text anywhere other than the first column. What am I doing wrong?</p>