Dear all,
I'm new to mdl. I have created the combobx. But i want to insert values into it. How to insert the values into it. Please help me.
my code for creating combobox is
DialogBoxRsc DIALOGID_RegSeaIcon ={
{ { 5.3*XC+3, 9.8*YC, 0, 0 }, Label, 0, ON, LABEL_FONT_BOLD, "Annotate" , "" }, { { 30*XC+3, 9.8*YC, 10*XC+5, 0 }, ComboBox, COMBOBOXID_Annotate, ON, 0,"","" },
}
DItem_ComboBoxRsc COMBOBOXID_Annotate ={ NOCMD, LCMD, NOSYNONYM, NOHELP, MHELP, HOOKITEMID_Annotate, NOARG, 2, "", "", "", "", NOMASK, 0, 6, 4, 0, 0, COMBOATTR_AUTOADDNEWSTRINGS,"", "", { {0, 12, 0, ""},}};
I have taken the {HOOKITEMID_Annotate, Annotate_hook},
So defining the function Annotate_hook now. I want to insert values in this function. Please help me.
Private void Annotate_hook( DialogItemMessage *dimP){
Regards,
Mythili
Build a ListModel. Assign the ListModel to your ComboBox in the item's _CREATE event. Destroy the ListModel in the item's _DESTROY event.
// DITEM_MESSAGE_CREATE ListModel* list = mdlListModel_create (NumCols); BuildMyList (list); mdlDialog_comboBoxSetListModelP (comboBox, list);
// DITEM_MESSAGE_DESTROY ListModel* list = mdlDialog_comboBoxGetListModelP (comboBox); mdlListModel_destroy (list, TRUE);
Regards, Jon Summers LA Solutions
Thank you jon for ur reply but i want to insert two string values like 'YES" and 'NO' in drop-down.
How to insert them. Please help me...
// Create a sting list and set the stringlist to the combobox. Private void Annotate_hook( DialogItemMessage *dimP){StringList *codeSL;
char codeValue[10];
RawItemHdr *riP;
codeSL = mdlStringList_create(6,1); mdlStringList_setMember(codeSL,0,"YES",NULL); mdlStringList_setMember(codeSL,1,"NO",NULL);
riP=dimP->dialogItemP->rawItemP; dimP->msgUnderstood=TRUE;
switch(dimP->messageType) { case DITEM_MESSAGE_USER: { mdlDialog_comboBoxSetStrListP(riP,codeSL,0); break; } case DITEM_MESSAGE_STATECHANGED: { mdlDialog_itemGetValue(NULL, NULL, codeValue, dimP->db, dimP->itemIndex, 10); break; } default: { dcomP->msgUnderstood=FALSE; break; } }}
Hope it will help.
Sundar
Thank you sundar for ur quick reply.
I have created my combobox with two values "YES" and "NO".
When i select an item from combobox, i should retrieve that element or index number.
Is it possible for combobox. Please help me. Thanks in advance.
Hi Mythili,
I don't understand what you mean element or index number in combobox.
But you can get the selected item (YES, NO) from the STATECHANGED event,
Thins is the MDL function to get the value,
mdlDialog_itemGetValue(NULL, NULL, codeValue, dimP->db, dimP->itemIndex, 10);
codeValue return the selected item. check the selected item by print the codeValue.
Hi Sundar,
I tried with that . But its not retrieving the value. I'm sending u the code, how i inserted the values into it. Please check it. Values are inserting.
Private void Annotate_hook( DialogItemMessage *dimP)
{
StringList *stringListP1;
Private RawItemHdr *comboBoxP1;
int row;
dimP->msgUnderstood = TRUE;
row=1;
switch (dimP->messageType)
case DITEM_MESSAGE_CREATE:
mdlDialog_openAlert("create");
comboBoxP1 = dimP->dialogItemP->rawItemP;
stringListP1 = mdlStringList_create (0,1);
mdlDialog_comboBoxSetStrListP(comboBoxP1,stringListP1,1);
mdlStringList_insertMember (&row , stringListP1 , -1 ,1);
mdlStringList_setMember (stringListP1,row,"YES ",NULL);
mdlStringList_setMember (stringListP1,row,"NO ",NULL);
break;
case DITEM_MESSAGE_STATECHANGED:
mdlDialog_openAlert(codeValue);
case DITEM_MESSAGE_DESTROY:
mdlStringList_destroy(stringListP1);
default:
dimP->msgUnderstood = FALSE;
Mythili.
In the above code you are using mdlDialog_comboBoxSetStrListP two times, I dont know what is the purpose of it.
If the combo box values are dynamic then only you go for mdlStringList_insertMember function, but in your case you already know the items(YES,NO)
Try by replacing the event DITEM_MESSAGE_CREATE to DITEM_MESSAGE_USER
Or just replace your code to,
stringListP1 = mdlStringList_create (2,1);
mdlStringList_setMember (stringListP1,0,"YES ",NULL);
mdlStringList_setMember (stringListP1,1,"NO ",NULL);
and one more thing I forger to said while getvalue you need to get the item index from the dialogitem so add one more line to get the dialogitem,
DialogItem *diP = NULL;
diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_ComboBox, COMBOBOXID_Annotate, 0);
mdlDialog_itemGetValue(NULL, NULL, codeValue, dimP->db, diP ->itemIndex, 10);
Sundar.
StringList is provided for legacy purposes. Prefer ListModel to StringList …
After allocating memory for either a StringList or ListModel you are responsible for deallocating memory using the appropriate destroy function.
When you've allocated a StringList or ListModel in the _CREATE event of a dialog hook function you should deallocate memory in that hook function's _DESTROY event.
Please solve my problem. I'm unable to retrieve the value selected in combobox. This is my code.
char stri[50];
mdlDialog_itemGetValue(NULL, NULL, stri, dimP->db, dimP->itemIndex, 50);
mdlDialog_openAlert(stri);
// printf ("value: %s\n", stri);
There are several examples of ComboBox in the MDL examples delivered with the SDK. Here's one answer that was posted some time ago on these Forums …
// [Matt Watkins] // Do the following in your comboboxes DITEM_MESSAGE_STATECHANGED. char buf [512]; ValueDescr valueDescr; RawItemHdr * pTextItem = mdlDialog_comboBoxGetTextP (dimP->dialogItemP->rawItemP); if (NULL != pTextItem) { valueDescr.value.charPFormat = buf; if (SUCCESS == mdlDialog_rItemValueGet (&valueDescr.formatType, &valueDescr.value, NULL, pTextItem, 512)) { if (strlen (valueDescr.value.charPFormat) > 0) { ULong newLevelId; MSWChar levelName [MAX_LEVEL_NAME_LENGTH]; if (0 != mdlCnv_convertMultibyteToUnicode (valueDescr.value.charPFormat, -1, levelName, MAX_LEVEL_NAME_LENGTH)) mdlLevel_create (&newLevelId, MASTERFILE, levelName, LEVEL_NULL_CODE); } } }