Thanks Aldo for the information!  I have included a sample dual listbox
interface program for anyone to try so that they can see how to apply what
you said(see Aldo's reply at bottom).  I move items from one listbox to the
other instead of copy.  The items remain sorted in both listboxes as items
are added and removed in any order. This will really work best for my
end-users.  Doing a copy to Listbox2 and leaving data in Listbox1 makes it
hard to determine what items have not been selected yet. My Listbox1 in my
application may contain over well over a 100 items and my end-users may need
to select a good many but not all those items.

Thanks again,
Eric Hansen

#-------------------------#
#------ START SCRIPT -----#
#-------------------------#

use Win32::GUI;
use Win32::Sound;

$W = new GUI::Window(
    -title    => "Continuously Sorted Dual Listboxes",
    -left     => 100,
    -top      => 100,
    -width    => 360,
    -height   => 170,
    -style    => 1024 | WS_BORDER | WS_CAPTION | WS_SYSMENU,
    -name     => "Window",
);

$List1 = $W->AddListbox(-name => "List1",
                        -style => WS_CHILD | WS_VISIBLE | 1 | WS_VSCROLL,
                        -left => 5,
                        -top  => 5,
                        -height => 120,
                        -tabstop => 1,
                        -group => 1,
                        -width => 100,
                        -sort => 1,);

addthem();

sub addthem{
        $List1->AddString("Item 5");
        $List1->AddString("Item 3");
        $List1->AddString("Item 1");
        $List1->AddString("Item 4");
        $List1->AddString("Item 2");
        $List1->Select(0);
        }

$List2 = $W->AddListbox(-name => "List2",
                        -style => WS_CHILD | WS_VISIBLE | 1 | WS_VSCROLL,
                        -left => 250,
                        -top  => 5,
                        -height => 120,
                        -sort => 1,
                        -tabstop => 1,
                        -group => 1,
                        -width => 100);

$Add   = $W->AddButton(-text  => "Add >",
                       -left  => 125,
                       -top   => 30,
                       -width => 100,
                       -tabstop => 1,
                       -group => 1,
                       -name  => "Add");

$Remove = $W->AddButton(-text  => "< Remove",
                        -left  => 125,
                        -top   => 65,
                        -width => 100,
                        -tabstop => 1,
                        -group => 1,
                        -name  => "Remove");

$Close = $W->AddButton(-text  => "Close",
                       -left  => 125,
                       -top   => 115,
                       -width => 100,
                       -tabstop => 1,
                       -group => 1,
                       -name  => "Close");

$W->Show;
GUI::Dialog();

sub Add_Click {
    my $sel = $List1->SelectedItem();
    if($sel != -1) {
        my $new = $List2->AddString($List1->GetString($sel));
        $List2->Select($new);
        $List1->RemoveItem($sel);
    } else {
        Win32::Sound::Play("SystemDefault", SND_ASYNC);
    }
}

sub Remove_Click {
    my $sel = $List2->SelectedItem();
    if($sel != -1) {
        my $new = $List1->AddString($List2->GetString($sel));
        $List1->Select($new);
        $List2->RemoveItem($sel);
    } else {
        Win32::Sound::Play("SystemDefault", SND_ASYNC);
    }
}

sub Close_Click {
    $W->PostQuitMessage(0);
}

sub Window_Terminate {
    $W->PostQuitMessage(0);
}

#----------------------#
#----- END SCRIPT -----#
#----------------------#

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Aldo "dada"
Calpini
Sent: Monday, December 06, 1999 8:09 AM
To: [EMAIL PROTECTED]
Subject: Re: [perl-win32-gui] Request for Continous Sorting in Dual
Listbox Interfaces


Eric C. Hansen wrote:
> Aldo, can the -sort property be enhanced in a future Win32::GUI release to
> continually keep the listbox items sorted as some items are removed and
then
> added back?  How does Visual Basic do this, or does it do this?

sorry, the functionality is there, I just missed to specify how it works.
for an item to be automatically added in correct sort order, you must use
the Add() or AddString() method. if you use InsertItem() instead, the
string is appended at the end of the list and no sort is done.
the docs will be corrected, thanks for pointing it out!

cheers,
Aldo

__END__
# Aldo Calpini
%_ = split undef, join ' ', qw(fahokem
xritajbugne csuctawer jhdtlrnpqloevkshpr
); print map $_{$_}, sort keys %_;





Reply via email to