Looks like I understood the idea behind the SetItemData and GetItem:
Changed my code to following , but i guess, now i can build my code upon this:
Code:
BOOL CMFCApplication2Dlg::OnInitDialog()
{
// TODO: Add extra initialization here
priya_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE);
int nItem = priya_list.InsertColumn(0, _T("Cell"), LVCFMT_LEFT, -1, 0);
priya_list.InsertColumn(1, _T("Site"), LVCFMT_LEFT, -1, 0);
int centralsite;
vector<int> sites;
bool bIsfirstCentralsite(false);
for (const auto pair : m)
{
bIsfirstCentralsite = true;
string centreId;
int index = pair.first;
if (index == 1)
{
centreId = "first";
}
else
{
centreId = "second";
}
CString ccetre(centreId.c_str());
for (const auto site : pair.second)
{
int nItem(0);
if (bIsfirstCentralsite)
nItem = priya_list.InsertItem(priya_list.GetItemCount(), ccetre);
else
nItem = priya_list.InsertItem(priya_list.GetItemCount(), _T(""));
auto itr = n.find(site);
string sSiteId = itr->second;
CString cSiteId(sSiteId.c_str());
priya_list.SetItemText(nItem, 1, cSiteId);
if (centreId == "first")
{
priya_list.SetItemData(nItem, (DWORD)(1));
}
else
priya_list.SetItemData(nItem, (DWORD)(2));
bIsfirstCentralsite = false;
}
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CMFCApplication2Dlg::OnBnClickedAddToSiteDB()
{
CListCtrl * priya_ctrl = (CListCtrl *) GetDlgItem(IDC_LIST1);
POSITION pos = priya_ctrl->GetFirstSelectedItemPosition();
int nItem = priya_ctrl->GetNextSelectedItem(pos);
int centreid = (int)priya_ctrl->GetItemData(nItem);
// derive the centre id string from this number
}