The answer is using ListView::FindItemWithText, read here on its use. Refer to my edit above for how I solved my exact issue.
VC++ 2010 search listview for a certain string
-
01-09-2022 - |
Pregunta
I have a listview created that I am adding data to and I want to avoid duplicates so I am searching the listview before I add the new item to it. I found some similiar code on here (I think?)
array<ListViewItem^>^ lvHostsSearch = lvHosts->Items->Find(gcnew String(myStr), false);
if(lvHostsSearch->Length == 0)
{
// Add Item to listbox since it was not found.
}
The MSDN page for the Find() method states that the return value is an array:
An array of ListViewItem objects containing the matching items, or an empty array if no items matched.
So that is why Its testing for an array of 0 length. Though it still keeps adding it over and over again? I know my logic must be wrong or seeing something wrong with this. Any help appreciated! Thanks!
EDIT (SOLVED):
I ended up FINALLY finding the way to search for text in a listview. As viewed on the MSDN page for it. I ended up doing something like:
if(myListView->FindItemWithText(myStr) == nullptr)
Hope it might help someone else out.
Solución