Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtGridCellComboBox::SetItemString Collapse All
Subject Author Date
Suhai Gyorgy Mar 30, 2007 - 9:16 AM

When I call CExtGridCellComboBox::SetItemString for the selected item, text of the cell doesn’t get changed. I’d like to do this in a PropertyGrid, so calling TextSet myself would mess up default-active state of the property (turning it bold). Could SetItemString check if it is the selected item and change text of cell accordingly? Thank you!

Technical Support Mar 30, 2007 - 12:03 PM

The combo box cell supports independently two types of text properties: cell text and text of each item. The selected item index is the third independent property of the combo box cell. On the one hand, the combo box cell is a simple text cell with a drop-down button. But the cell’s text is assigned from the list box when the user selects it and the combo box common control with an edit control inside works in the same way. You can invoke its CWnd::SetWindowText() method and set any custom text that may be different from the strings you can see in the list box.

But the CExtGridCellComboBox cell class supports a special enumeration mode which resets the index of the selected string. The enumeration mode also allows you to change the selected string by double clicking the cell’s text area. It can be turned on with CExtGridCellComboBox::SetEnumMode() method.

If you don’t need the combo box cell in the enumeration mode due to some of its specific behavior in this mode, the it’s not difficult to code a small combo box cell class in scope of your project and make it working as you want:

// INSERT THIS CODE IN SOME HEADER FILE IN YOUR PROJECT
class CAutoSelectTextCellComboBox : public CExtGridCellComboBox
{
public:
      DECLARE_SERIAL( CAutoSelectTextCellComboBox );
      IMPLEMENT_ExtGridCell_Clone( CAutoSelectTextCellComboBox, CExtGridCellComboBox );
      CAutoSelectTextCellComboBox(
            CExtGridDataProvider * pDataProvider = NULL
            )
            : CExtGridCellComboBox( pDataProvider )
      {
      }
      virtual ~CAutoSelectTextCellComboBox ()
      {
      }
      virtual void TextSet(
            __EXT_MFC_SAFE_LPCTSTR str = __EXT_MFC_SAFE_LPCTSTR(NULL), // empty text
            bool bAllowChangeDataType = false
            )
      {
            ASSERT_VALID( this );
            CExtGridCellComboBox::TextSet( str, bAllowChangeDataType );
            if( GetEnumMode() )
                  return; // the rest of the work is already done in CExtGridCellComboBox::TextSet ()
            LONG nNewCurSel =
                  FindStringExact( str );
            if( nNewCurSel < 0 )
            {
                  if( _tcscmp( str, _T("") ) != 0 )
                        SetCurSel( -1, true );
                  return;
            }
            LONG nOldCurSel = GetCurSel();
            if( nNewCurSel == nOldCurSel )
                  return;
            SetCurSel( nNewCurSel );
      }
};

// INSERT THIS CODE IN SOME SOURCE FILE IN YOUR PROJECT BEFORE MFC’s DEBUG new OPERATOR DECLARATION
IMPLEMENT_SERIAL( CAutoSelectTextCellComboBox, CExtGridCellComboBox, VERSIONABLE_SCHEMA|1 );