Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Determining PtList Selection: (6 Items)
   
Determining PtList Selection  
I am attempting to determine which item is selected in a PtList control.

I am currently using this code:
-----------------------------------
unsigned short* pnSelPos = 0;
short*                pnItem    = 0;

PtGetResource(ABW_ListBarcodes, Pt_ARG_SELECTION_INDEXES, &pnSelPos, &pnItem);
-----------------------------------

Pt_ARG_SELECTION_MODE is set to: Pt_SINGLE_MODE

It seems that *pnSelPos identifies the currently selected item.  However, when nothing is selected *pnSelPos can still 
have a value.

Can someone explain to me what *pnSelPos and *pnItem represent in this context and if there is another way to retrieve 
which item is currently selected if any?

Thank you,
Kendall

AW: Determining PtList Selection  
Hi,

I think *pnItem should be the number of currently selected item.

Cheers,
Thomas

----- Originalnachricht -----
Von: Kendall Russell [mailto:community-noreply@qnx.com]
Gesendet: Wednesday, May 25, 2011 01:37 PM
An: photon-graphics <post86139@community.qnx.com>
Betreff: Determining PtList Selection

I am attempting to determine which item is selected in a PtList control.

I am currently using this code:
-----------------------------------
unsigned short* pnSelPos = 0;
short*                pnItem    = 0;

PtGetResource(ABW_ListBarcodes, Pt_ARG_SELECTION_INDEXES, &pnSelPos, &pnItem);
-----------------------------------

Pt_ARG_SELECTION_MODE is set to: Pt_SINGLE_MODE

It seems that *pnSelPos identifies the currently selected item.  However, when nothing is selected *pnSelPos can still 
have a value.

Can someone explain to me what *pnSelPos and *pnItem represent in this context and if there is another way to retrieve 
which item is currently selected if any?

Thank you,
Kendall





_______________________________________________

Photon microGUI
http://community.qnx.com/sf/go/post86139
Re: AW: Determining PtList Selection  
Well, here are a few scenarios that I ran and the values for those variables:

Scenario 1: PtList Widget is empty

pnSelPos == 0
*pnSelPos == 0
pnItem == has an address
*pnItem == 0

Scenario 2: PtList Widget has 4 items with the 3rd item highlighted.

*pnSelPos == 3
*pnItem == 1

Scenario 3: PtList Widget has 5 items with nothing highlighted 

*pnSelPos == 61692
*pnItem == 0


So, if the PtList widget has items and one is highlighted, then it appears that *pnSelPos is correct.  If the PtList 
Widget is empty, the return seems correct to me.  The only thing that doesn't seem correct is if the PtList Widget has 
contents, but nothing is selected.  (Scenario 3)


> Hi,
> 
> I think *pnItem should be the number of currently selected item.
> 
> Cheers,
> Thomas
> _______________________________________________
> 
> Photon microGUI
> http://community.qnx.com/sf/go/post86139


Re: AW: Determining PtList Selection  
It's an array resource.  pnItem points to the length and pnSelPos to the array elements, if any.  When *pnItem is zero, 
that means that the array has zero elements and you're not supposed to even look at *pnSelPos (a.k.a. pnSelPos[0]) 
because it's outside of the array.
Re: AW: Determining PtList Selection  
> It's an array resource.  pnItem points to the length and pnSelPos to the array
>  elements, if any.  When *pnItem is zero, that means that the array has zero 
> elements and you're not supposed to even look at *pnSelPos (a.k.a. pnSelPos[0]
> ) because it's outside of the array.


So, is there a better or easier way to determine which item in a PtList widget is selected?
Re: AW: Determining PtList Selection  
> So, is there a better or easier way to determine which item in a PtList widget
>  is selected?

I can't think of anything better or easier than

  PtGetResource(ABW_ListBarcodes, Pt_ARG_SELECTION_INDEXES, &pArr, &pLen);
  if ( *pLen == 0 ) {
    printf( "Nothing is selected\n" );
  } else {
    printf( "Item #%d is selected\n", pArr[0] );
  }