Re: NEWT :: selecting an item from a listbox

new topic     » goto parent     » topic index » view thread      » older message » newer message

Dirt simple, once you figure out what to do. I still have no idea how to used the pointer value which Newt would assign by default.

-- 
-- simple euphoria newt list box demo 
-- 
-- Demonstrates how to pass an integer "key" (sequence index) to the  
-- newt application which may be used to access a list box selection,  
-- instead of allowing the application to-- set an arbitrary pointer  
-- to the value selected. 
 
include ../newt.e 
include std/machine.e 
include std/console.e 
 
constant LIST =    { "Apples", "Bannanas", "Oranges" } 
integer LIST_LENGTH = length(LIST) 
procedure main() 
     
    -- create a simple list of things  
     
    newtComponent form,  
    ListBoxItem, 
    buttonSubmit 
     
    newt:Init() 
    newt:Cls() 
     
    -- create a new list box  
    newt:CenteredWindow( 
	58,                                 -- width 
	24,                                 -- height 
	"*Select Item"                      -- title 
	) 
     
    ListBoxItem = newt:Listbox(  
	18,                                 -- left 
	3,                                  -- right  
	LIST_LENGTH,                        -- height  
	NEWT_FLAG_SCROLL                    -- flag 
	)  
     
    -- loop through the items  
    for index = 1 to length( LIST ) do  
	--  add the item to the list box  
	newt:ListboxAppendEntry(     
	    ListBoxItem,  
	    LIST[index],                    -- text 
	    index                           --<==== key, integer will now be returned  
	    )                               --           instead of pointer assigned   
    end for                                 --           by application. 
     
    buttonSubmit = newt:Button( 22, 20, "Submit" ) 
     
    form = newt:Form( NULL, NULL, 0 ) 
    newt:FormAddComponents( form, { ListBoxItem, buttonSubmit } ) 
     
    --// run the form here //--  
    newt:FormRun(form) 
     
    -- display the result  
    printf( 1, "you selected: %s\n", {LIST[newt:ListboxGetCurrent( ListBoxItem )]} )  
    any_key() 
     
    newt:FormDestroy(form) 
    newt:Finished() 
end procedure 
main() 

Ken

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu