I have a grid with a CString

Article ID: 38
Last updated: 16 Apr, 2018
Article ID: 38
Last updated: 16 Apr, 2018
Revision: 3
Views: 1732
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 16 Apr, 2018
by Meltreger B.

Problem


I have a grid with a CString in column 1 and before the user is allowed to enter another string in one of the other grid rows, I want to check to make sure there are no duplicate strings in the grid. How can I do that?


Cause



Action


A very simple solution would be to cycle through each row of the grid and compare each string, but this is very inefficient. As already explained in the previous question, StoreStyleRowCol() is an ideal override for preparing information because it is always called when a cell is changed.

I would suggest that you override StoreStyleRowCol() and check:

if (style.GetIncludeValue())

If this is TRUE, you could insert the string in an associative collection like CMapStringToWord. Later, when you need to check if the string is already there, you can look in the collection if the string is already there and you don't have to loop through all rows any more. This technique will improve performance significantly.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 38
Last updated: 16 Apr, 2018
Revision: 3
Views: 1732
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 16 Apr, 2018 by Meltreger B.

Others in this category