in reply to Win32:GUI Combo Boxes

Thanks for showing code, and for keeping your code snippet down to a manageable size.

Of course your code doesn't populate the data. Even if the AddComboBox method paid any attention to the -InsertItem hash key (which I doubt), that slot in the hash could still hold only one value, and each additional value would overwrite its predecessor.

Try assigning the return value of your ComboBox constructor to an instance variable, so that you can call the InsertItem method on that instance.

my $combo_box = $main->AddComboBox( ...); $combo_box->InsertItem( 'One' ); $combo_box->InsertItem( 'Two' ); $combo_box->InsertItem( 'Buckle my shoe' );

I haven't tested this.

Take a look at The Win32::GUI Documentation Project.

Replies are listed 'Best First'.
Re^2: Win32:GUI Combo Boxes
by Karger78 (Beadle) on Aug 31, 2009 at 17:38 UTC
    Thanks for your suggestion. It might be better if you get a full look at my code.
    use Win32::GUI(); $main = Win32::GUI::Window->new( -name => 'Main', -width => 500, -height => 500, -text => 'Auto Log', ); $main->AddCombobox( -name => "combo_box", -width => 120, -height => 110, #-tabstop=> 1, -pos => [5,160], -dropdownlist=> 0, ); my $combo_box = $main->AddComboBox( $combo_box->InsertItem( "One" ), $combo_box->InsertItem( "Two" ), $combo_box->InsertItem( "Buckle my shoe" ), ); $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; }
    Now with code you supplied, now I get this error. "Can't call method "InsertItem", on a undefined value"

      Paste the code I supplied over the version you typed.

      Then you will have to replace my ellipsis (...) in the AddComboBox call with the proper argument list (try the one you supplied to your first AddCombobox call).

      Please pay attention to punctuation. To a programmer, there is all the difference in the world between a comma and a semicolon.

      Hello, Thanks for your answers. After looking at it a bit better. Here is what I added to make it work correctly.
      $main->AddCombobox( -name => "combo_box1", -width => 120, -height => 110, #-tabstop=> 1, -pos => [5,160], -dropdownlist=> 0, ); $main->combo_box1->InsertItem("One");
      Thanks once again for your help.