Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, i am hoping you can help me. I am using the Win32::GUI module and i have a listview added. I am trying to catch a button-click on a column name so i can sort on that column. I am looking through the documentation but i can't find anything. Here is what i have so far:

use strict; use warnings; use Win32::GUI(); use DBI; my $mw = Win32::GUI::Window->new( -text => "View", -size => [ 550, 500 ], -pos => [ 200, 200 ], ); sub mw_Terminate { return -1 } my $lv = $mw->AddListView( -pos => [ 20, 20 ], -size => [ 400, 400 ], -gridlines => 1 ); $lv->InsertColumn( -item => 0, -text => "PID", -width => 50); $lv->InsertColumn( -item => 1, -text => "Name", -width => 100); $lv->InsertColumn( -item => 2, -text => "Address", -width => 100); $lv->InsertColumn( -item => 3, -text => "Salary", -width => 100); my $dbfile = 'C:/code/lqs.db'; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","",""); my $stmt = qq(select id,name,address,salary from deliver order by sala +ry desc); my $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]]); } $mw->Show; Win32::GUI::Dialog();

Replies are listed 'Best First'.
Re: Win32::Gui listview column click
by Anonymous Monk on Aug 19, 2018 at 11:52 UTC

    Sure:

    use strict; use warnings; use Win32::GUI(); use DBI; my $mw = Win32::GUI::Window->new( -text => "ListView", -size => [ 500, 500 ], -pos => [ 200, 200 ], ); sub mw_Terminate { return -1 } my $lv = $mw->AddListView( -name => "view", -pos => [ 20, 20 ], -size => [ 400, 400 ], -gridlines => 1 ); $lv->InsertColumn( -item => 0, -text => "PID", -width => 50); $lv->InsertColumn( -item => 1, -text => "Name", -width => 100); $lv->InsertColumn( -item => 2, -text => "Address", -width => 100); $lv->InsertColumn( -item => 3, -text => "Salary", -width => 100); my $dbfile = 'C:/code/lqs.db'; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","",""); my $stmt = qq(select id,name,address,salary from deliver order by sala +ry desc); my $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]]); } $mw->Show; Win32::GUI::Dialog(); sub view_ColumnClick{ my $var = shift; $lv->DeleteAllItems; if($var == 0){ $stmt = qq(select id,name,address,salary from deliver order by + id asc); $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]] +); } } elsif($var==1){ $stmt = qq(select id,name,address,salary from deliver order by + name asc); $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]] +); } } elsif($var==2){ $stmt = qq(select id,name,address,salary from deliver order by + address asc); $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]] +); } } elsif($var==3){ $stmt = qq(select id,name,address,salary from deliver order by + salary asc); $sth = $dbh->prepare($stmt); $sth->execute; while(my @row = $sth->fetchrow_array()){ $lv->InsertItem(-text => [$row[0],$row[1],$row[2],$row[3]] +); } } }

    Any comments are welcome.

        No particular reason. In the past i have used it a little. What do you recommend?

Re: Win32::Gui listview column click
by Anonymous Monk on Aug 18, 2018 at 14:18 UTC

    I already figured it out, so nevermind.

      for completeness, can you also post your solution and musings? Thanks.
Re: Win32::Gui listview column click
by Anonymous Monk on Aug 20, 2018 at 07:49 UTC

    I have cleaned it up a bit.