Author |
Topic |
|
tinkusch
Germany
94 Posts |
Posted - 07/21/2021 : 4:14:00 PM
|
Origin Pro 2018G, SR1, Win10
need some help with the Multiselect_ListBox. I wrote a dialog function with a multiselect listbox in ORIGIN C:
int Dialog1()
{
GETN_TREE(tree1)
GETN_MULTISEL_LISTBOX(Menu, "Select ", 0, "A|B|C|D|E")
if(GetNBox(tree1, Dialog1Node_event , "Dialog title"))
{
return 0;
}
return 1;
}
The following Dialog1Node_event function should evaluate the selection:
int Dialog1Node_event(TreeNode& tree1, int nRow, int nEvent, DWORD& dwEnables,
LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux,
string& strErrMsg)
{
TreeNode trEdited;
switch(nEvent)
{
case GETNE_ON_VALUE_CHANGE:
trEdited = tree_get_node(tree1, nRow);
vector<string> vsOnlySubNode;
tree_get_values(trEdited, vsOnlySubNode, true);
out_int("size ",vsOnlySubNode.GetSize());
for(int ii=0;ii<vsOnlySubNode.GetSize();ii++)
printf("subnode string %s\n",vsOnlySubNode[ii]);
break;
}
out_tree(trEdited);
return 1;
}
The dialog works with the below output if all enrtries are selected: size 1 subnode string AAAAAAEAAAACAAAAAwAAAAQAAAA= Select = 5:{0, 1, 2, 3, 4}
It seems that the tree is ok but the subnode string looks odd and seemingly cannot be evaluated this way. So what is wrong with the code? What is the best way to evaluate the dialog? What data type does GETN_MULTISEL_LISTBOX return? Any help or comments welcome, thanks, Stefan
|
|
cpyang
USA
1406 Posts |
Posted - 07/21/2021 : 8:24:07 PM
|
GETNE_ON_VALUE_CHANGE unfortunately does not have lpcszNodeName so you will need to use nRow, which is not as clean as using tree node name, so just test it is better, see the code below.
static int Dialog1Node_event(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
string strNode = lpcszNodeName;
if(strNode == "list") {
vector<int> vnSel;
vnSel = tr.list.nVals;
for(int ii = 0; ii < vnSel.GetSize(); ii++) {
printf("%d: %d\n", ii+1, vnSel[ii]);
}
}
return true;
}
void tms()
{
vector<string> vsFruits = {"Apple", "Orange", "Banana", "Berries", "Grapes"};
string strCombo;
strCombo.SetTokens(vsFruits, '|');
GETN_TREE(tr)
GETN_MULTISEL_LISTBOX(list, "Select", 0, strCombo)
if(GetNBox(tr, Dialog1Node_event , "Dialog title"))
{
vector<int> vnSel;vnSel = tr.list.nVals;
for(int ii = 0; ii < vnSel.GetSize(); ii++) {
string strName = vsFruits[vnSel[ii]];
printf("%d: %s\n", ii+1, strName);
}
}
}
Basically multiple selection give you a vector of the selected entries with the row index.
CP
|
|
|
tinkusch
Germany
94 Posts |
Posted - 07/22/2021 : 05:01:23 AM
|
works... Thank you |
|
|
|
Topic |
|
|
|