Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing of ComboBox

Status
Not open for further replies.

mpsoutine

Programmer
Jan 6, 2003
87
US
Hi,

I'm would like to initialize a ComboBox with the contents from a table in a database. Has anyone seen a good tutorial on how to properly do this.

Thanks,
MPSoutine
 
Until someone suggests a better solution, you can have an ADO recordset with the information you want, then have a while loop add values and move to the next record until reaching Recordset.EOF.
 
If your database table is large, another method is to use the bulk field exchange functions. They're a little tricky (at least for me) but are much faster for large amounts of data.
 
Hi,

I was able to get it to work using the code below. What I want to do next is store the information of the buyer and seller in another table. I'm using a Customer table to populate the ComboBox. Next I want select a buyer and seller from the ComboBox and then store those two names in a Transaction table. My question is what is the correct value to store in the Transaction table: the m_CustomerID,m_CustomerName or the value from SetItemData. The way I understand SetItemData is that it is used to set a unique value to each index. Any thoughts on this?




Soutine

CCustomerSet TmpSet;
CCustomerSet* m_pSet = &TmpSet;


CComboBox* pBuyerBox;
CComboBox* pSellerBox;
pBuyerBox = &m_cbBuyer;
pSellerBox = &m_cbSeller;






if(TmpSet.IsOpen())

TmpSet.MoveFirst();

else
TmpSet.Open();

int nBuyerIndex;
int nSellerIndex;



while(!TmpSet.IsEOF())
{

nBuyerIndex = pBuyerBox->AddString(TmpSet.m_CustomerName);
nSellerIndex = pSellerBox->AddString(TmpSet.m_CustomerName);

pBuyerBox->SetItemData(nBuyerIndex,TmpSet.m_CustomerID);
pSellerBox->SetItemData(nSellerIndex,TmpSet.m_CustomerID);

TmpSet.MoveNext();
}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top