vc 我想把 单位编号 单位名称 存在 下拉列表中 选择单位名称 也能得到 单位编号
在别的语言中如 下拉列表.value =单位编号   下拉列表.txt=名称 
怎么办了,希望有个完整的例子

解决方案 »

  1.   

    估计你选择的是combobox吧,如果两个combobox,在添加数据的时候,就要保证数据的一致性,插入数据的话,都用InsertString(index,str);这样的方式
    然后,用:ON_CBN_SELCHANGE中,选择变化的时候,同时通知另外一个变化,只要SetCurSel(index)来设置另外一个当前的选择,就能保持一致;
    取值的话,只要根据INDEX取,就一致了!
      

  2.   

    用SetItemData和GetItemData具体查MSDN中mboBox::SetItemData和mboBox::GetItemData
    ==========================================
    CComboBox::SetItemData
    int SetItemData( int nIndex, DWORD dwItemData );Return ValueCB_ERR if an error occurs.ParametersnIndexContains a zero-based index to the item to set.dwItemDataContains the new value to associate with the item.ResSets the 32-bit value associated with the specified item in a combo box. Use the SetItemDataPtr member function if the 32-bit item is to be a pointer.Example// The pointer to my combo box.
    extern CComboBox* pmyComboBox;// Set the data of each item to be equal to its index.
    for (int i=0;i < pmyComboBox->GetCount();i++)
    {
       pmyComboBox->SetItemData(i, i);
    }===============================
    CComboBox::GetItemData
    DWORD GetItemData( int nIndex ) const;Return ValueThe 32-bit value associated with the item, or CB_ERR if an error occurs.ParametersnIndexContains the zero-based index of an item in the combo box’s list box.ResRetrieves the application-supplied 32-bit value associated with the specified combo-box item. The 32-bit value can be set with the dwItemData parameter of a SetItemData member function call. Use the GetItemDataPtr member function if the 32-bit value to be retrieved is a pointer (void*).Example// The pointer to my combo box.
    extern CComboBox* pmyComboBox;// If any item's data is equal to zero then reset it to -1.
    for (int i=0;i < pmyComboBox->GetCount();i++)
    {
       if (pmyComboBox->GetItemData(i) == 0)
       {
          pmyComboBox->SetItemData(i, (DWORD) -1);
       }
    }