How to insert values into combobox.

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

Parents
  • 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

     
    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...

    Regards,

    Mythili

  • // 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.

    Regards,

    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.

    Regards,

    Mythili

  • 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.

    Regards,

    Sundar

  • 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;

     char codeValue[10];

      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_insertMember (&row , stringListP1 , -1 ,1);

    mdlStringList_setMember (stringListP1,row,"NO ",NULL);

            mdlDialog_comboBoxSetStrListP(comboBoxP1,stringListP1,1);

          }

          break;

          case DITEM_MESSAGE_STATECHANGED:

          {

                mdlDialog_itemGetValue(NULL, NULL, codeValue, dimP->db, dimP->itemIndex, 10);

    mdlDialog_openAlert(codeValue);

          }

         break;

         case DITEM_MESSAGE_DESTROY:

          mdlStringList_destroy(stringListP1);

          break;

          default:

             dimP->msgUnderstood = FALSE;

          break;

      }

    }

    Regards,

    Mythili.

  •  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_insertMember (&row , stringListP1 , -1 ,1);

    mdlStringList_setMember (stringListP1,row,"NO ",NULL);

            mdlDialog_comboBoxSetStrListP(comboBoxP1,stringListP1,1);

    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);

    mdlDialog_comboBoxSetStrListP(comboBoxP1,stringListP1,1);

    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);

    Regards,

    Sundar.

  • Prefer ListModel to StringList

    StringList is provided for legacy purposes. Prefer ListModel to StringList …

    1. More flexible & versatile
    2. Better structured
    3. Stores values not strings
    4. Display can differ from value

    After allocating memory for either a StringList or ListModel you are responsible for deallocating memory using the appropriate destroy function.

    Managing Memory in Hook Functions

    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.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Prefer ListModel to StringList

    StringList is provided for legacy purposes. Prefer ListModel to StringList …

    1. More flexible & versatile
    2. Better structured
    3. Stores values not strings
    4. Display can differ from value

    After allocating memory for either a StringList or ListModel you are responsible for deallocating memory using the appropriate destroy function.

    Managing Memory in Hook Functions

    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.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Children
  • Please solve my problem. I'm unable to retrieve the value selected in combobox. This is my code.

    case DITEM_MESSAGE_STATECHANGED:

           {

     char stri[50];

    diP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_ComboBox, COMBOBOXID_Annotate, 0);

    mdlDialog_itemGetValue(NULL, NULL, stri, dimP->db, dimP->itemIndex, 50);

    mdlDialog_openAlert(stri);

    // printf ("value: %s\n", stri);

          }

         break;

         case DITEM_MESSAGE_DESTROY:

          mdlStringList_destroy(stringListP1);

          break;

          default:

             dimP->msgUnderstood = FALSE;

          break;

    Regards,

    Mythili.

  • 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);
            }
        }
    }

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions