How to avoid value repetition in the CListCtrl
-
Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.
You can iterate through the list and remove duplicate ones no? Also there are useful
stl
algorithms likeunique
which works on a sorted list, so before inserting you can callunique
on the list.Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.
Why don't you check before inserting? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.
you can traverse thorough the list to see if the element you are going toinsert already exist or not. if it exsist dont insert. otherwise insert.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
You can iterate through the list and remove duplicate ones no? Also there are useful
stl
algorithms likeunique
which works on a sorted list, so before inserting you can callunique
on the list.Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
Hi Thomas, How can i call unique before inserting value to list. kindly can you clarify me. Thank.
Murugan k wrote:
How can i call unique before inserting value to list.
You can use unique only if you have a std::list/vector/etc with you which instead you are inserting to a list control. But since you are directly inserting to the list control use CListCtrl::FindItem, if found don't insert. I guess this will help?
Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com