From: Brian R. (G. H. School) <Row...@gr...> - 2007-09-19 09:04:44
|
Hi all Enjoy reading all the help emails generated by this group so thought I'd ask for some help please with listview. I've used TheLoft to create a gui interface for a program I'm writing. A button I click is meant to read a selected line from a listview pane and display the results in a selection of tf / cb controls: # determine which rows have been selected my @selection =3D $win-> lvwFleece-> SelectedItems(); =20 my $size =3D @selection; # determine how many rows have been selected my %temp; # hash for reading listview data my $field; # field name to match column heading if ((@selection) and ($size =3D=3D 1)) { # display the one row selected foreach my $c (0..$max_fleece-1) { %temp =3D $win-> lvwFleece-> GetItem($selection[0],$c); $field =3D $fleece_fields[$c]; $win-> $field-> Text("$temp{-text}"); } } The code works and produces the required output but I have some queries that puzzle me. 1. @selection contains the index values of the rows selected. However, if no rows are selected I was expecting it to be return a () array but printing its size in such a case shows a value of 1. Why would that be? 2. I really need some better way to determine if the listview has been clicked. The event ItemClick(ITEM) in the package description for listview looks as though it could be a better option for me. Can someone kindly help me to construct the line to determine if the listview has had a line selected please? I'm still learning perl and I'm puzzled how to do this simple task. Thanks Brian Rowlands We must accept finite disappointment, but we must never lose infinite hope. Martin Luther King Jr. </quotes/k/martinlutherking/> =20 |
From: Jason P. <jp...@da...> - 2007-09-19 10:44:01
|
Hi Brian, 1) Selection will contain -1 when there are no selections, I believe (this is from memory and from 1.02/1.03 so, check) 2) With all those mentions of fleece, are writing financial software? 3) ItemClick indeed would likely be the better choice over this 4) In the Loft, specify that the list is a single selection list, as it appears our code seems to be entirely single selection. _____ From: per...@li... [mailto:per...@li...] On Behalf Of Brian Rowlands (Greymouth High School) Sent: Wednesday, September 19, 2007 4:58 AM To: per...@li... Subject: [perl-win32-gui-users] Listview mental block Hi all Enjoy reading all the help emails generated by this group so thought I'd ask for some help please with listview. I've used TheLoft to create a gui interface for a program I'm writing. A button I click is meant to read a selected line from a listview pane and display the results in a selection of tf / cb controls: # determine which rows have been selected my @selection = $win-> lvwFleece-> SelectedItems(); my $size = @selection; # determine how many rows have been selected my %temp; # hash for reading listview data my $field; # field name to match column heading if ((@selection) and ($size == 1)) { # display the one row selected foreach my $c (0..$max_fleece-1) { %temp = $win-> lvwFleece-> GetItem($selection[0],$c); $field = $fleece_fields[$c]; $win-> $field-> Text("$temp{-text}"); } } The code works and produces the required output but I have some queries that puzzle me. 1. @selection contains the index values of the rows selected. However, if no rows are selected I was expecting it to be return a () array but printing its size in such a case shows a value of 1. Why would that be? 2. I really need some better way to determine if the listview has been clicked. The event ItemClick(ITEM) in the package description for listview looks as though it could be a better option for me. Can someone kindly help me to construct the line to determine if the listview has had a line selected please? I'm still learning perl and I'm puzzled how to do this simple task. Thanks Brian Rowlands We must accept finite disappointment, but we must never lose infinite hope. <file:///\\quotes\k\martinlutherking\> Martin Luther King Jr. |
From: Ned C. <Ned...@mo...> - 2007-09-27 14:11:18
|
Hi all, =20 I have what I think is a simple question on what should be a common use fro Win32::GUI. =20 I want to build a screen that will display an input "Enter foo:" =20 Then will display another input "Enter bar:" =20 =20 All I want to do is be able to press enter or click ok for each input. =20 When I press enter, $bar has the first input $foo as its data? =20 It seems to me that this should be documented somewhere? And even some sample code? =20 Is this module dead? =20 =20 Thankx =20 Ned Cunningham =20 Monro Muffler Brake, Inc. (585) 784-3310 <mailto:ned...@mo...> =20 =20 |
From: Robert M. <rob...@us...> - 2007-11-10 11:06:48
|
On 19/09/2007, Brian Rowlands (Greymouth High School) <Row...@gr...> wrote: > I've used TheLoft to create a gui interface for a program I'm writing. A > button I click is meant to read a selected line from a listview pane and > display the results in a selection of tf / cb controls: > > # determine which rows have been selected > my @selection = $win-> lvwFleece-> SelectedItems(); > > 1. @selection contains the index values of the rows selected. However, > if no rows are selected I was expecting it to be return a () array but > printing its size in such a case shows a value of 1. Why would that be? Bug, in my opinion. There is similar behaviour throughout the XS code where the return value from subs that are expected to return lists is incorrect for there being no values - the subs return undef rather than the empty list. You'll find the one item in the list is undef. I'm fixing them as I find them, despite the change being non-backwards compatible, as it's very useful to be able to write: # process all selected items for ($win->SelectedItems()) { process_item($_); } rather than what you have to do now: # process all selected items for ($win->SelectedItems()) { next if not defined $_; process_item($_); } or some equivalent. So long as code handles both empty lists and the undefined value case, then there is no backwards-compatibility issue. Backwards compatibility issues may occur with any code that assumes the list has at least one entry and check the first value in the list for definedness. > 2. I really need some better way to determine if the listview has been > clicked. The event ItemClick(ITEM) in the package description for > listview looks as though it could be a better option for me. Can > someone kindly help me to construct the line to determine if the > listview has had a line selected please? I'm still learning perl and > I'm puzzled how to do this simple task. Does this help? #!perl -w use strict; use warnings; use Win32::GUI qw(); my $mw = Win32::GUI::Window->new( -title => "ListView - Report Mode", -size => [400,300], ); $mw->AddListView( -name => "LV", -width => $mw->ScaleWidth(), -height => $mw->ScaleHeight(), -report => 1, -singlesel => 1, -onItemClick => \&itemSelected, ); for my $col_name ("Title", "Card Number", "Shelf Location") { $mw->LV->InsertColumn( -text => $col_name, -width => 100, ); } $mw->LV->InsertItem( -text => [ "Green Eggs and Ham", "JF SEU", "Children's", ], ); $mw->LV->InsertItem( -text => [ "A Brief History of the Universe", "897.112", "2nd Floor", ], ); $mw->LV->InsertItem( -text => [ "Your Book Title Here", "501.2", "Vault", ], ); $mw->Show(); Win32::GUI::Dialog(); exit(0); sub itemSelected { my ($self, $item) = @_; my %info = $self->GetItem($item); print qq(Selected: "$info{-text}"\n); return 1; } __END__ Regards, Rob. |