-
ComboBox index problem
Hi, I'm using a combobox setup and I have all my data listed in the box like so:
LVD-PTB
LVD-THS
LVD-RECEIVING
OTHER
I do an UpdateData and use a pointer to the IDC control pointing to the variable for that IDC and then use the value of that pointer to a string, based off of an exampled posted by Velius in a previous posting to another user.
Everything seems to be working but when I select the value:
LVD_PTB and test to see if thats actually the value I am getting, it is not. I have to select the 3rd value:
LVD-RECEIVING
to get the value LVD-PTB.
I'm guessing I have an idex issue not getting the correct location of the string. Does anyone see where I'm going wrong?
Code:
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_COMBOBOX);
CString str;
pCB->GetWindowText(str);
-
sorry it might help if I include all of the code:
Code:
m_Dropdown;
char data [8] = "LVD-PTB";
UpdateData ();
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_COMBO1);
CString str;
pCB->GetWindowText(str);
if ((strcmp(m_Dropdown, data)==0))
{
MessageBox("LVD-PTB");
}
-
Where is that code being called?
gg
-
Code:
void ISREPAIR::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
m_Dropdown;
char data [8] = "LVD-PTB";
UpdateData ();
CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_COMBO1);
CString str;
pCB->GetWindowText(str);
if ((strcmp(m_Dropdown, data)==0))
{
MessageBox("LVD-PTB");
}
}
My thought was just to call the update code whenever the droplist was accessed which I thought could be done with the above code. Hope that answers your question about where I'm calling the code. I'm just using the combobox's function I added to its class OnSelchange.
-
You don't need to call UpateData() since you are accessing the combo box directly.
I should of noticed this earlier, but what you'll want call is GetCurSel() and GetLBText().
gg
-
based off the msdn site, it looks like I have use GetCurSel() and set an int equal to whatever that returns, then use GetLBText() at that int and place that value into a string?
Does that appear to be correct, because I am getting alot of compiler errors trying to combine these two functions.... I think is just my inabiltiy to read the examples off msdn.
Most of my errors are from trying to use variables as parameters in the function calls.
But I'll keep trying if I have the concept right... to use those functions.
-
Code:
pCB->GetLBText(pCB->GetCurSel(), str);
gg
-
Wow, thats good stuff Codeplug. Thank you. Another really cool lesson learned. Thanks for the help.