Objective Grid: Retrieving the current text from a combobox

Article ID: 437
Last updated: 27 Apr, 2018
Article ID: 437
Last updated: 27 Apr, 2018
Revision: 3
Views: 3168
Posted: 11 Jan, 2001
by Meltreger B.
Updated: 27 Apr, 2018
by Meltreger B.

Problem

 


How can I get the current text from a combo box whenever the user selected a new item in a combo box?

 

 


Cause

 


 

 


Action

 


If you are using CGXComboBox, you should override OnModifyCell( ) and call pControl->GetValue( ) to get the current text of the cell.

Example:

void CGXWndEx::OnModifyCell(ROWCOL nRow, ROWCOL nCol)
{
CGXGridWnd::OnModifyCell(nRow, nCol);
CGXControl* pControl = GetControl(nRow, nCol);
pControl->GetValue(strValue);
TRACE("OnModifyCell %s ", strValue );
}

With CGXComboBoxWnd there is a minor problem because CComboBox sends the CBN_SELCHANGE method before it updates the edit box portion of the control. Therefore pControl->GetValue( ) returns the old value.

The following code works around that problem:

BOOL CGXWndEx::OnCommand(WPARAM wParam, LPARAM lParam)
{

#if _MFC_VER <0x0300

UINT nNotification = HIWORD(lParam);
HWND hCtl = (HWND) LOWORD(lParam);
#else
UINT nNotification = HIWORD(wParam);
HWND hCtl = (HWND) lParam;
#endif
if (nNotification == CBN_SELCHANGE)
{
CGXComboBoxWnd* pControl = (CGXComboBoxWnd*) GetCurrentCellControl();
CString strValue;
pControl->GetLBText(pControl->GetCurSel(), strValue);
TRACE("Combobox changed %s ", strValue );
}

BOOL bResult = CGXGridWnd::OnCommand(wParam, lParam);
return bResult;

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 437
Last updated: 27 Apr, 2018
Revision: 3
Views: 3168
Posted: 11 Jan, 2001 by Meltreger B.
Updated: 27 Apr, 2018 by Meltreger B.

Others in this category