PDA

View Full Version : Tabbed Combo Box: Validation fails when choice list is changed dynamically



nasar
09-08-2017, 01:35 AM
Initialize a tabbed combo box with a list. Let's call it "DefaultList"
Change the choice list in GetStyleRowCol or OnLoadCellStyle overridable functions. Let's call it "CustomList"
"CustomList" is displayed in combo box.
In OnValidateCell when try to get value from combo box. It always return empty. Actually the control has the older style object with "DefaultList".



The issue is that the control returned by GetControl(nRow, nCol) always has the initial style object with "DefaultList".

Environment: Visual Studio 2015, Stingray Studio 12.0

It was working fine in Visual Studio 2008 with Stingray Studio 2004




// Initialize tabbed combo box
m_grid1.SetStyleRange(CGXRange().SetCols(1),
CGXStyle()
.SetControl(GX_IDS_CTRL_TABBED_COMBOBOX)
.SetChoiceList(_T("T00\t0\nT11\t1\nT22\t2\n"))
.SetUserAttribute(GX_IDS_UA_TABLIST_KEYCOL, _T("1"))
.SetUserAttribute(GX_IDS_UA_TABLIST_TEXTCOL, _T("0"))
.SetUserAttribute(GX_IDS_UA_TABLIST_SHOWALLCOLS, _T("0"))
.SetHorizontalAlignment(DT_LEFT)
);




// Change Choice List
BOOL CSample2GridWnd::OnLoadCellStyle(ROWCOL nRow, ROWCOL nCol, CGXStyle & style, LPCTSTR pszExistingValue)
{
if (nCol == 1)
{
if (pszExistingValue == NULL && nRow >= GetFirstRow() && !m_bNoValueNeeded)
{
style.SetChoiceList(_T("Test 0\t0\nTest 1\t1\nTest 2\t2\n"));
style.SetValue(m_str[nRow-1]);
}
}

CGXBrowserWnd::OnLoadCellStyle(nRow, nCol, style, pszExistingValue);

return TRUE;
}




// validation routine
BOOL CSample2GridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
{
if (nCol != 1)
return TRUE;

CString str;

// retrieve text from current cell
CGXControl* pControl = GetControl(nRow, nCol);
pControl->GetCurrentText(str);
str.Trim();
if (str.IsEmpty())
AfxMessageBox(_T("Please select a value from list."));

m_str[nRow-1] = str.Right(1);

return TRUE;
}