Objective Grid: Determining combobox dropdown list items at runtime

Article ID: 179
Last updated: 04 Jun, 2018
Article ID: 179
Last updated: 04 Jun, 2018
Revision: 3
Views: 6145
Posted: 23 Jan, 2001
by Meltreger B.
Updated: 04 Jun, 2018
by Meltreger B.

Problem


How can I create a subclassed combo box where the dropdown list items are determined at runtime?


Cause



Action


You have several choices:

  1. Take a look at the article "How can I fill the choice list of a combo box depending on a value in another cell?". This lets you supply the choice list at runtime.
  2. You can derive a class from CGXComboBoxWnd and implement an owner drawn combo box. See the article "How can I implement an owner-drawn combo box?"
  3. You might subclass a control from CGXComboBox as in the following example:

Example:

// see CGridSample5View (gridsvw5.cpp) for info on how
// to register subclassed controls.
//
// CMyComboBox is a sample class

class CMyComboBox: public CGXComboBox
{

DECLARE_CONTROL(CMyComboBox);
public:
// Constructor & Destructor
CMyComboBox(CGXGridCore* pGrid, UINT nEditID, UINT nListBoxID, UINT nFlags);
~CMyComboBox( );

// Override these methods if you don't want to fill the
// list from the choice-list
virtual void OnStoreDroppedList(CListBox* lbox);
virtual void OnFillDroppedList(CListBox* lbox);

};

// CMyComboBox

CMyComboBox::CMyComboBox(CGXGridCore* pGrid, UINT nEditID, UINT nListBoxID, UINT nFlags)

: CGXComboBox(pGrid, nEditID, nListBoxID, nFlags)
{
m_bFillWithChoiceList = FALSE;
}

CMyComboBox::~CMyComboBox( )
{

}

void CMyComboBox::OnFillDroppedList(CListBox* lbox)
{

const CGXStyle& style = Grid( )->LookupStyleRowCol(m_nRow, m_nCol);

// fill with Choices at runtime
{

while (...)
{
CString sItem;

...

lbox->AddString(sItem);

}
}

// Set Window Text and select item
CString s;

if (IsActive( ))

GetWindowText(s);
else
s = style.GetValueRef( );
// Select item
lbox->SetCurSel(atoi(s));

// or
lbox->SelectString(-1, s);

}

void CMyComboBox::OnStoreDroppedList(CListBox* lbox)
{

// Save the selection
int index = lbox->GetCurSel( );

if (index != LB_ERR)
{

CString s;
char sz[20];
lbox->GetText(index, s);
SetActive(TRUE);
SetWindowText(s);
SetSel(0,-1);
SetModify(TRUE);
Invalidate( );
}
}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 179
Last updated: 04 Jun, 2018
Revision: 3
Views: 6145
Posted: 23 Jan, 2001 by Meltreger B.
Updated: 04 Jun, 2018 by Meltreger B.

Others in this category