How to figure out if a column-header in a listmodel is clicked?

Hi,

I've created a sortable by column listmodel using the attribute LISTATTR_SORTCOLUMNS. I want to know if a user clicks on the column-header to sort the listmodel, but I can't seem to find any any event/hook that will do that for me.

Anyone? Thanks!

Parents
  • Data Containers and Data Display Dialog Items

    Unknown said:
    I've created a sortable by column listmodel using the attribute LISTATTR_SORTCOLUMNS

    No, you haven't.  A ListModel is a data container: it has no properties concerning display.  A ListBox is a dialog item: it has properties that concern how it displays itself (LISTATTR_XXX macros), but it contains no data.  A ListBox uses either a StringList or, preferably, a ListModel to store its data.

    Your ListBox should have a dialog item MDL hook function that you use to create and monitor it.  Your hook function should handle several events, including DITEM_MESSAGE_CREATE, DITEM_MESSAGE_DESTROY etc.  Use the DITEM_MESSAGE_BUTTON event to monitor button clicks on your ListBox.  The Datasheet example illustrates this.

    In that event, sort your ListModel, then tell the ListBox to redraw itself because something changed (e.g. mdlDialog_listBoxNRowsChanged()).

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Data Containers and Data Display Dialog Items

    Unknown said:
    I've created a sortable by column listmodel using the attribute LISTATTR_SORTCOLUMNS

    No, you haven't.  A ListModel is a data container: it has no properties concerning display.  A ListBox is a dialog item: it has properties that concern how it displays itself (LISTATTR_XXX macros), but it contains no data.  A ListBox uses either a StringList or, preferably, a ListModel to store its data.

    Your ListBox should have a dialog item MDL hook function that you use to create and monitor it.  Your hook function should handle several events, including DITEM_MESSAGE_CREATE, DITEM_MESSAGE_DESTROY etc.  Use the DITEM_MESSAGE_BUTTON event to monitor button clicks on your ListBox.  The Datasheet example illustrates this.

    In that event, sort your ListModel, then tell the ListBox to redraw itself because something changed (e.g. mdlDialog_listBoxNRowsChanged()).

     
    Regards, Jon Summers
    LA Solutions

Children
  • Thanks Jon for your quick reply!

    Unknown said:
    No, you haven't.  A ListModel is a data container: it has no properties concerning display.

    You're right of course. I actually did create a listbox with a listmodel as data container.

    Your ListBox should have a dialog item MDL hook function that you use to create and monitor it. Your hook function should handle several events, including DITEM_MESSAGE_CREATE, DITEM_MESSAGE_DESTROY etc.  Use the DITEM_MESSAGE_BUTTON event to monitor button clicks on your ListBox.  The Datasheet example illustrates this.

    Check! I'm using the DITEM_MESSAGE_BUTTON event to monitor if a cell was clicked and mdlDialog_listBoxLastCellClicked to find the correct cell. Works like a charm. But how do I determine if a column-header is clicked (that's how the user sorts the listbox)? I've kinda got it to work by looking at the 'pt' in the 'button'-structure, to find out if the user clicked somewhere inside the column-header-rectangle, but that's not enough to determine a 'sortby column'-action was performed. Because the user could've clicked in between column-headers (to maximize the column-width).

    Looking at DITEM_MESSAGE_STATECHANGED also doesn't help, because clicking in between column-headers also generates a statechanged-event.

    In that event, sort your ListModel, then tell the ListBox to redraw itself because something changed (e.g.mdlDialog_listBoxNRowsChanged()).

    I don't need to sort the ListModel, because as far as I can tell the LISTATTR_SORTCOLUMNS-attribute is doing that for me. Currently I'm not doing any sorting myself, but my end-result (after I write the ListModel to a textfile) is sorted correctly.

    I only want to know if the user performed a 'sort.by column'-action.

    Cheers! Jan

  • Hi Jan,

    > I only want to know if the user performed a 'sort.by column'-action.

    One possible, albeit 'hackish', way would be to hook your own sort callback function with mdlListColumn_setSortFunction() and whenever it was called by the listbox you would know for sure that sorting took place on this particular column...

    Cheers,

    /Chris Z.

  • I know this is a very old thread but had a similar question as Jan but for a non-sorting issue: "...But how do I determine if a column-header is clicked?" so I thought I'd revive it. Here's the solution:

    case DITEM_MESSAGE_BUTTON:
            {
            if (dimP->u.button.buttonTrans == BUTTONTRANS_UP)
                {
                if ((mdlDialog_listBoxLastCellClicked(&row, &col, dimP->dialogItemP->rawItemP)) == SUCCESS)
                    {
                    if (row == -2) //got a column header click
                        {
                        switch(col)
                        ...

    mdlDialog_listBoxLastCellClicked() returns row as -2 only when a column header is clicked (not when sized).  Note that this is undocumented in current API docs so may change without notice.