Combox SetItemData索引与数据绑定

1. 数据结构


typedef struct PartType_s 

 CString KeyValue;               
 CString KeyIndex;
 
}PartType_t;

 

2.初始化数据

while(!m_pRecordset->adoEOF)
  {
   // _variant_t vIndex = (long)0;
   
   //_variant_t vCount = m_pRecordset->GetCollect(vIndex);
   
   UpdateData();

   PartType_t *mPartType=new PartType_s;
   
   mPartType->KeyValue=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");

   mPartType->KeyIndex=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID");
   
   lvItemIndex=m_com_team_a.AddString(mPartType-> KeyValue);
   
   m_com_team_a.SetItemData(lvItemIndex,(DWORD)mPartType);

   lvItemIndex=m_com_team_b.AddString(mPartType-> KeyValue);
   
   m_com_team_b.SetItemData(lvItemIndex,(DWORD)mPartType);

 
   UpdateData(false);
   
   m_pRecordset->MoveNext(); 
  }

 

3.select

 

 int sel = m_com_team_a.GetCurSel(); 

 PartType_t * mPartType = NULL; //=new PartType

 mPartType = (PartType_t*)m_com_team_a.GetItemData(sel);
 
 CString NameA=mPartType->KeyValue;
 int IdxA=atoi(mPartType->KeyIndex);

你可能感兴趣的:(Combox SetItemData索引与数据绑定)