Fusion Invest/Capital: how to use the autocompletion control?
Oct
10
Written by:
10/10/2014 8:07 AM
Using the Sophis toolkit, it is possible to display a list when typing in a edit control. For example, in the default native transaction dialog, some references of instruments appear once the first characters are filled. The class that permits to reproduce this behaviour is CSRInstrumentCode which inherits from CSRGenericAutoCompletion. According to the comments provided in the sphcode.h header, there should be a sample in a SphSrc/AutoCompletion folder... Unfortunately, I haven't found such a sample, and looking for questions/answers on the Sophis support forum, I only have found one question without answer. This post will show how to implement some code in order to get the expected result, it means giving a list of results when typing some characters as follow:
In fact I haven't found how to use the parent class directly. My first tentative implemented the pure virtual methods for the value getter/setter and CreateSuggestionList. It didn't work, CreateSuggestionList was never called. I've tried to call the Initialize as indicated in the comments too, same result.
Finally, I've derivated my class from the child class CSRInstrumentCode, and overriden the CreateSuggestionList methods as follow:
ITQBasketSwapEdit::ITQBasketSwapEdit(CSRFitDialog* dlg,
int
id)
: inherited(dlg,id)
{
}
void
ITQBasketSwapEdit::CreateSuggestionList()
{
ClearWholeList();
struct
SSBasketSwapReferences
{
long
m_sicovam;
char
m_reference[SIZE_INSTRUMENT_REF+1];
};
CSRStructureDescriptor _desc(2,
sizeof
(SSBasketSwapReferences));
ADD(&_desc,SSBasketSwapReferences,m_sicovam,rdfInteger);
ADD(&_desc,SSBasketSwapReferences,m_reference,rdfString);
int
_count = 0;
SSBasketSwapReferences* _results = NULL;
errorCode _err = CSRSqlQuery::QueryWithNResults(
"select sicovam,reference from titres where modele='Basket Swap'"
,&_desc,(
void
**)&_results,&_count);
if
(_err==0)
{
for
(
int
i=0; i<_count; i++)
AddItemToWholeList (_results[i].m_reference);
// array is a string array of array_size size.
delete
[] _results;
}
}
void
ITQBasketSwapEdit::CreateSuggestionList(
const
char
* prefix)
{
CreateSuggestionListFromWholeList(prefix);
}
And it works fine!