Hey!
i will try to explain my question better here and my situation 🙂
i have a ListView in my application, this ListView is used for output errors , so its kinda used for error log.
My program is mainly a timer, that is checking for changes in int values.
when an error occurs I want to show it in my list.
Problem is that the error will then be added like 3-4 times, maybe more.
If i do a check if(exist.in.listbox) i will not be able to add the same error second time. What I want to do is to delete specific message/error and then delete it when its “fixed” or no longer a threat to the system.
here is code snippet:
if (Convert.ToInt32(x) == 1 && Convert.ToInt32(y) == 1)
{
found = false;
ListViewItem item = new ListViewItem(message);
foreach (ListViewItem z in listView1.Items)
{
if (z.Text == message)
{ found = true; }
}
if (found == false)
{
item.SubItems.Add(now.ToString());
listView1.Items.Add(item);
listView1.EnsureVisible(item.Index);
}
}
else
{
foreach (ListViewItem z in listView1.Items)
{
if (z.Text == message)
{
//no longer a threat, delete the message added aboue
}
}
}
cant find anything about this. only “when selected –> delete the line”
can think about this like the error window in visual, when u get a red error, u can fix the code.and it disapair 🙂
You should follow the same approach as when you add items. First, check if you want to perform the deletion, and then remove the item.
If this does not perform well (iterating through the list twice on each timer iteration), you could also move your “add/remove” logic out of the ListView (ie, maybe keep a Dictionary for faster lookup).