Reputation: 846
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.
Upvotes: 1
Views: 3743
Reputation: 1084
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
Upvotes: 2