1

I created a program where you can put text in a richtextbox with a button. When the button is clicked the text from this textbox is put in a listview with a checkbox on each line. This listview only has 1 column.

Now, I want to put some lines in as a subitem and to remove the checkbox from the parents, like a tree. However, I only see the parents at the moment, the subitems are not showing. I also don't know how to remove the checkbox from the parents.

I saw the treeview class, but I don't want the those dots before each line and I don't know if you can add checkboxes there.

This is my code

    private void ParseButton_Clicked(object sender, EventArgs e)
    {
       string[] entries = rawLogBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

       ListViewItem parent = null;
       foreach (string entry in entries)
       {
           if (Regex.IsMatch(entry, "^={10} .* ={10}$"))
           {
               parent = new ListViewItem(entry);
               parsedLogBox.Items.Add(parent);
           }
           else
           {
               if (parent == null)
               {
                   parsedLogBox.Items.Add(new ListViewItem(entry));
               }
               else
               {
                   new ListViewItem.ListViewSubItem(parent, entry);
               }
           }                 
       }
       parsedLogBox.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
    }

The listview is set to detail.

Aaron
  • 826
  • 10
  • 22

1 Answers1

2

You have to add the SubItems like so:

parent.SubItems.Add(entry)

see also this so question

Edit: for controlling checkboxes in a treeview: TreeView Remove CheckBox by some Nodes

Community
  • 1
  • 1
Jobo
  • 1,084
  • 7
  • 14
  • 1
    Same result, I think this is because it adds them in a different column on the same row. But I only have 1 column and I want them 1 entry per row. I'd also like the parents to be able expand and minimize, like a tree. – Aaron Dec 29 '12 at 12:06
  • SubItems will always appear in the next column. Maybe you could enhance your question a little bit. Expand and minimize is not possible with the standard listview. You can however have checkboxes in a treeview, see my edit of the answer. – Jobo Dec 29 '12 at 13:00
  • 1
    I'm using a treeview atm, it's better, but not perfect. I'll change the lay-out a bit more as I want it. I'm accepting your answer as I won't be needing more help. – Aaron Dec 29 '12 at 13:38