+1  A: 

SetItemData(DWORD) or SetItemDatPtr(void*) IIRC.

Rob
+1  A: 

You have a function that maps item index to database ID. There is no built-in inverse for that function because the general case doesn't have an inverse. A single data value might map to many different items in the list control; the OS doesn't know your data values are unique.

Your technique of searching the control items one by one is the only way to do it, unless you have additional information stored elsewhere. As you populate your combo box, you could build a reverse index in a std::map. When you add item i with database ID id, add an entry to your other data structure, too:

SetItemData(i, id);
reverse_index[id] = i;

Then, instead of searching one item at a time, you can just look in the index, replacing your loop with this:

std::map<DWORD_PTR, int>::iterator it = reverse_index.find(nId);
if (it != reverse_index.end()) {
  assert(GetItemData(*it) == nId);
  SetCurSel(*it);
  hr = S_OK;
}
Rob Kennedy