Get the selected item from ListBrowserList [Solved]

8 posts / 0 new
Last post
Nube
Nube's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-09-10 02:09
Get the selected item from ListBrowserList [Solved]

Hi,
I am trying to get the text of the selected element of the listbrowser but I can only get the last element of the list..

This is the list of the listbrowser gadget:

  1. CONST_STRPTR nodetexts[] = {
  2. "rastan",
  3. "outrun",
  4. "vigilante",
  5. "shinobi",
  6. NULL
  7. };
  8.  
  9. STRPTR lb_selected; // var to store selected item

and this is the piece of code that I use to get the selected item:

  1. case OID_BSTART:
  2. IListBrowser->GetListBrowserNodeAttrs((struct Node *)node,
  3. LBNA_Column,0,
  4. //LBNA_Selected, TRUE,
  5. LBNCA_Text,&lb_selected,
  6. TAG_DONE);
  7. IDOS->Printf("listbrowser element:%s\n",lb_selected);
  8. break;

If I try to put LBNA_Selected, TRUE, I get a GR when I press the OID_BSTART gadget..

With the code above i always get the last element of the list that is "shinobi".

In my gui I have only one listcolumn.

Am I missing some tag inside the GetListBrowserNodeAttrs or do I have to put some loop code to check what the user is selecting??

Thanks

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 17 hours ago
Joined: 2013-05-30 00:53
Re: Get the selected item from ListBrowserList

Try to get selectednode first (example is when double clicked on listbrowser entry):

  1. uint32 res_node;
  2. int32 res_value;
  3. STRPTR res_text, res_cmd;
  4. ...
  5. case WMHI_GADGETUP:
  6. switch(result & WMHI_GADGETMASK)
  7. {
  8. case GID_P_LISTBROWSER:
  9. IIntuition->GetAttr(LISTBROWSER_RelEvent, OBJ(GID_P_LISTBROWSER), &res_value);
  10. if(res_value == LBRE_DOUBLECLICK)
  11. {
  12. IIntuition->GetAttr(LISTBROWSER_SelectedNode, OBJ(GID_P_LISTBROWSER), (uint32 *)&res_node);
  13. int32 month, *pday;
  14. ...

and then the items/values you want/need:

  1. IListBrowser->GetListBrowserNodeAttrs( (struct Node *)res_node,
  2. //LBNA_Column,COL_MM, LBNCA_Integer,&pmonth,
  3. LBNA_Column,COL_DD, LBNCA_Integer,&pday,
  4. LBNA_Column,COL_TEXT, LBNCA_Text,&res_text,
  5. LBNA_Column,COL_CMD, LBNCA_Text,&res_cmd,
  6. TAG_END);

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Nube
Nube's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-09-10 02:09
Re: Get the selected item from ListBrowserList

Hi Jabirulo!

Thanks for the help! I was able to discover two more my mistake I did with listbrowser object. I forgot to put

  1. GA_ID, objects[OID_LISTBROWSER],
  2. GA_RelVerify, TRUE,

tag inside the NewObject() function so this was my first mystake and that's why it cannot get the event inside the listbrowser object.
Then, using your code I was able to get the name of the selected item.
Thank you, problem solved! :-)

Nube
Nube's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-09-10 02:09
Re: Get the selected item from ListBrowserList

is it possible to mark the question as "Solved"?

trixie
trixie's picture
Offline
Last seen: 5 months 2 weeks ago
Joined: 2011-02-03 13:58
Re: Get the selected item from ListBrowserList

@Nube

You'll need to edit the title of this thread.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

Nube
Nube's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-09-10 02:09
Re: Get the selected item from ListBrowserList [Solved]

Thanks Trixie :-)

broadblues
broadblues's picture
Offline
Last seen: 4 years 2 months ago
Joined: 2012-05-02 21:48
Re: Get the selected item from ListBrowserList [Solved]

If I try to put LBNA_Selected, TRUE, I get a GR when I press the OID_BSTART gadget..

No one seems to have addressed this point.

The problem with this is that you are attempting to SET the attribute to TRUE in a GET function. What this means in practice is that the browser attempts to write the value of the selected state into the int32 pointed to by the address 0x00000001 (ie TRUE taken as an address). This will inevitably crash.

I suppose there is some confusion created by the fact you can set LBNA_Column to select which column attrs to fetch, this the only tag where you can do this. (And prety horrid design if you think about logically, but it is what it is).

Nube
Nube's picture
Offline
Last seen: 4 years 11 months ago
Joined: 2012-09-10 02:09
Re: Get the selected item from ListBrowserList [Solved]

Thanks broadblues, you are totally right, I didn't see this big error! i was trying to Set a TagItem using the Get function!!!...

Again thank you :-)

Log in or register to post comments