Listbox Cursor

Hii all,

 A form has a listbox with two columns named description and cellname. While creating the listbox, i'm loading description and cellnames into listbox from database.But i'm opening this dialogbox when i accept a cell.So,i'm able to retrieve the cellname which i picked(accept) from the drawing and able to find the row number of that cellname where it is hiding in the listbox. But i need the cursor to move to that row while dialogbox loading itself. For my code,its defaultly, the cursor is residing at the first row. Cursor means the blue color indication. So,please help me with some code.

 

Regards,

Mythili

  • As Jon would say: A Line of Code is worth thousand words.

    Why not showing us, how the listbox is defined in the .r and how you defined your callbacks for filling and position handling ?!



  • mdlDialog_listBoxAPI

    The mdlDialog_listBoxXxx API provides many ways of interacting with a ListBox.

    Most of the time you use that API inside a hook function (callback function) …

    case DITEM_MESSAGE_STATECHANGED:
    {
        ListRow*        pRow        = NULL;
        ListModel*      pListModel  = mdlDialog_listBoxGetListModelP (pLBox);
        int             nRows       = mdlListModel_getRowCount (pListModel);
    
        if (!dimP->u.stateChanged.reallyChanged)
           break;
    
        mdlDialog_listBoxLastCellClicked (&m_nRow, &m_nCol, pLBox);
    
        if (pListModel && 0 < nRows)
        {
            pRow  = mdlListModel_getRowAtIndex (pListModel, m_nRow);
        }
        break;
    }

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • DItem_ListBoxRsc LISTBOXID_Description_Cellname_EditIn =

    {

        NOHELP,

        LHELP,

        HOOKITEMID_Description_Cellname_EditIn,

        NOARG,

        LISTATTR_GRID|LISTATTR_DYNAMICSCROLL|LISTATTR_RESIZABLECOLUMNS,    

        6,

        0,

        //TXT_lBox_ConsumerList,

        "",

            {

            {50*XC, 60, ALIGN_LEFT, "Description"},

            {20*XC, 60, ALIGN_LEFT, "Cellname"},

            }

    };

    Hookitemid is {HOOKITEMID_Description_Cellname_EditIn, Edit_Des_Cell_hook},

    Private void Edit_Des_Cell_hook(DialogItemMessage *dimP)

    {

       StringList *stringListP1;

       int rowIndex=0,colIndex=0,found,status;

       char buffer[400],desc[50],cellnm[30];

       MS_sqlda sqlda;

       dimP->msgUnderstood = TRUE;

       switch (dimP->messageType)

       {

       case DITEM_MESSAGE_CREATE:

           listBoxP1 = dimP->dialogItemP->rawItemP;

           stringListP1 = mdlStringList_create (0,2);

           str1=NULL;

           mdlDialog_listBoxSetStrListP(listBoxP1, stringListP1, 2);

           mdlDialog_listBoxDrawContents(listBoxP1, -1, -1);

           strcpy(buffer,"select * from iconlist where Signal_Class= 'INPUT' order by cellname");

           mdlDB_activeAutoCommitMode(OFF);

           mdlDB_openCursor(buffer);

           mdlDB_openCursor(buffer);

           while(mdlDB_fetchRow( &sqlda) != QUERY_FINISHED)

           {

               sprintf (desc, "%s" ,sqlda.value[5]);

               sprintf (cellnm, "%s" ,sqlda.value[2]);

               mdlStringList_insertMember(&colIndex, stringListP1, -1, 2);

               mdlStringList_setMember(stringListP1, colIndex, desc, NULL);

               mdlStringList_setMember(stringListP1, colIndex+1, cellnm, NULL);

               rowIndex++;

               colIndex++;

           }

           mdlDB_closeCursor();

           mdlDB_freeSQLDADescriptor(&sqlda);

           mdlDB_activeAutoCommitMode(ON);

           mdlDialog_listBoxSetStrListP (listBoxP1, stringListP1,2);

           mdlDialog_listBoxDrawContents(listBoxP1, -1, -1);

           break;

          default:

           dimP->msgUnderstood = FALSE;

           break;

       }

    }

    This is my code. On create event, i'm going to load the cellnames into listbox from stringlist. After loading the cursor is pointing to first row. But i need the cursor to point to some specified row with blue color on Create event itself.

    I'm OK with statechange event..when i'm changing with row by row, cursor is moving.

    Example: If i specify the row number is 3, on create event, the cursor should set to 3rd column.Please help me.

    Regards,Mythili

  • Have you tried mdlDialog_listBoxSetLocationCursor with the specific row (and first column) after the list was filled ?

    I do currently not work with MDL dialogs, therefore I have unfortunately no example, but this came in mind.



  • Yes, I tried with that by passing row n column number.But its not working.

  • ListBox Events

    happynjoy said:
    After loading the cursor is pointing to first row. But I need the cursor to point to some specified row with blue color on Create event itself.

    The time to set your initial state is in the DITEM_MESSAGE_INIT event rather than DITEM_MESSAGE_CREATE.

    At the time DITEM_MESSAGE_INIT is called your dialog item is initialised internally. To be more precise, I think that the start up events in order are …

    1. DITEM_MESSAGE_CREATE
    2. DITEM_MESSAGE_SETSTATE
    3. DITEM_MESSAGE_INIT

    You can test this by putting DEBUG statements in your hook function to trace events …

    char buffer [128];
    switch (dimP-&gt;messageType)
    {
        case DITEM_MESSAGE_CREATE:
        {
        	sprintf (buffer, "Event: %s", "DITEM_MESSAGE_CREATE");
        	mdlOutput_messageCenter (MSG_DEBUG, buffer, buffer, FALSE);
    	    break;
        }
        case DITEM_MESSAGE_SETSTATE:
        {
        	sprintf (buffer, "Event: %s", "DITEM_MESSAGE_SETSTATE");
        	mdlOutput_messageCenter (MSG_DEBUG, buffer, buffer, FALSE);
    	    break;
        }
        case DITEM_MESSAGE_INIT:
        {
        	sprintf (buffer, "Event: %s", "DITEM_MESSAGE_INIT");
        	mdlOutput_messageCenter (MSG_DEBUG, buffer, buffer, FALSE);
    	    break;
        }
          …
    }

    Prefer ListModel to StringList

    StringList is a relic from V7. Prefer the ListModel as a better-structured way to store data in memory. With V8, you can assign a ListModel as the data source of a ListBox.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions