|
-
December 22nd, 2020, 06:41 AM
#2
Re: ListCtrl in MFC
I don't know MFC, and I last used win32 API when XP was the current OS!
However, for testing I used a vector of pair to simulate the list and displayed to the console. Given:
Code:
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <utility>
#include <iomanip>
using namespace std;
int main()
{
const map<int, vector<int>> m = {{ 1, {1,3,4 }} ,{ 2, {4,5,6 } }};
const map<int, string> n = {{ 1, "Site1", } , { 2, "Site2"} ,{ 3, "Site3" },{ 4, "Site4" },{ 5, "Site5" },{ 6, "Site6" }};
vector<pair<string, string>> output;
bool bIsfirstCentralsite {false};
for (const auto pair : m) {
string centreId;
bIsfirstCentralsite = true;
if (pair.first == 1)
centreId = "first";
else
centreId = "second";
for (const auto site : pair.second) {
if (bIsfirstCentralsite)
output.emplace_back(centreId, "");
else
output.emplace_back("", "");
const auto itr {n.find(site)};
if (itr != n.end())
output.back().second = itr->second;
bIsfirstCentralsite = false;
}
}
for (const auto& out : output)
cout << left << setw(8) << out.first << setw(8) << out.second << '\n';
}
This displays:
Code:
first Site1
Site3
Site4
second Site4
Site5
Site6
so this algorithm seems OK. The issue would appear to be in use of the list control.
PS It looks like the list is being sorted by site. Are there any sorting criteria set anywhere?
Last edited by 2kaud; December 22nd, 2020 at 06:53 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|