ComboBox index problem

This is a discussion on ComboBox index problem within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm using a combobox setup and I have all my data listed in the box like so: LVD-PTB LVD-THS ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    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);

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    164
    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");
    	}

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    Where is that code being called?

    gg

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    164
    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.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    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

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    164
    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.

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    Code:
    pCB->GetLBText(pCB->GetCurSel(), str);
    gg

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    164
    Wow, thats good stuff Codeplug. Thank you. Another really cool lesson learned. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting index of chosen item in the combo box
    By what3v3r in forum Windows Programming
    Replies: 4
    Last Post: 09-01-2006, 11:49 AM
  2. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  3. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 10:11 PM
  4. Combobox problem
    By gargamel in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2005, 01:37 PM
  5. deleting a node by index
    By mouse163 in forum C++ Programming
    Replies: 4
    Last Post: 02-24-2005, 07:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21