Dear Kevin :

Thanks your help  and it's working good  for my purpose.

I find some issue about the column click event disappear in this case . 
And the column resize event and scrolling event seems not support  to let 
me capture it.
Since you tell me to edit the subitem on the ListView  has not  standard 
Windows function. I try the other way to implement this case. Maybe the 
Grid View more fit my target .
thanks so much .

Here is your sample I put a little event  processing to avoid that 
ListView resize event and  scrolling event  has been triggered .

 
#!perl
use strict;
use warnings;
use Win32::GUI qw();
use Win32::GUI::Constants qw(/^WS_/ /^VK_/);
 
my $MW = Win32::GUI::Window->new(
                                   -name  => 'MW',
                                    -size  => [350,550],
                                    -pos  => [250,125],
                                    -text  => "Listview Example",
                                    -pushstyle => WS_MINIMIZEBOX | 
WS_SYSMENU,
                                );

my $LV_0 = $MW->AddListView(
                             -name    => "LV_0",
                             -size    => [300,500],
                             -pos    => [6,6],
                             -fullrowselect  => 1,
                             -hottrack   => 0, 
                             -gridlines   => 1, 
                             -checkboxes   => 0,
                             -singlesel   => 1,
                             -oneclickactivate => 1,
                             -editlabel   => 1, 
                             -visible   => 1,
                             -nocolumnheader  => 0,
                           );

my $timer = $MW -> AddTimer( "Update", 300 ); 

my($Item,$SubItem);

my $Edit = Win32::GUI::Textfield->new(
                                      -parent   => $LV_0,
                                      -name   => 'Edit',
                                      -visible  => 0,
                                      -popexstyle  => WS_EX_CLIENTEDGE,
                                      -onLostFocus => sub {
                                                            #Label isn't 
changed if user clicks off textfield
                                                            my $self = 
shift; 
                                                            $self->Hide();
                                                            $timer -> 
Interval(300);
                                                            return 1;
                                                           },
                                      -onKeyDown => sub {
 my($self,$flags,$vkey) = @_;
                                                          #Label is 
changed on RETURN key
                                                          if($vkey == 
VK_RETURN){
                                                              my $item = 
$LV_0->Item($Item);
 if($SubItem){
                                                                  my $sub 
= $item->SubItem($SubItem);
 $sub->Text($self->Text());
                                                                }else{
 $item->Text($self->Text());
                                                                      }
 $self->Hide();
                                                            }
                                                          #Label isn't 
changed on ESCAPE key
                                                            elsif($vkey == 
VK_ESCAPE){
 $self->Hide();
                                                                 }
                                                          $timer -> 
Interval(0);
                                                          return 1;
                                                         },
                                                        );
$LV_0->InsertColumn(
 -index => 1,
 -width => 150,
 -text => "Column_0",
);

$LV_0->InsertColumn(
 -index => 2,
 -width => 1000,
 -text  => "Column_1",
);

for(0..100){
 $LV_0->InsertItem ( -text => [ ( sprintf "index %03d", $_ ), ( sprintf 
"subindex %03d", $_ ) ] );
}

$MW -> Show();
Win32::GUI::Dialog();
exit(0);

sub MW_Terminate{
 -1;
}

sub LV_0_MouseDblClick {
 my($x,$y,$flags) = @_;
 my($item, $subitem, $flag) = $LV_0->SubItemHitTest($x,$y);
 return 1 unless defined $item;
 my @rect;
 if($subitem){
  @rect = $LV_0->GetSubItemRect($item,$subitem);
 }
 else {
  @rect = $LV_0->GetItemRect($item);
 }
 $Edit->Show();
 $Edit->Left($rect[0]);
 $Edit->Top($rect[1]);
 $Edit->Width($rect[2]-$rect[0]);
 $Edit->Height($rect[3]-$rect[1]);
 $Edit->Text($LV_0->GetItemText($item,$subitem));
 $Edit->SelectAll();
 $Edit->SetFocus();
 $Item = $item;
 $SubItem = $subitem;
 return 1;
}

sub Update_Timer{
$LV_0 -> Redraw(1);
}

sub LV_0_MouseMove{
$Edit -> Hide();
$timer -> Interval(300);
}

__END__

Best Regards
Miller Chen




寄件人:
Kevin Marshall <kejoh...@hotmail.com>
收件人:
<miller_c...@sercomm.com>, Perl-Win32-GUI-Users List 
<perl-win32-gui-users@lists.sourceforge.net>
日期:
2009/11/23 上午 09:56
主旨:
RE: [perl-win32-gui-users] How to edit ListView subitem ?



Miller,
 
After digging through the Windows SDK documentation, I'm fairly certain 
that Windows doesn't allow subitem labels to be edited. You can get around 
this, though, by handling the label change yourself. 
 
Here is a sample I put together from your code that allows subitems to be 
edited. It does this by responding to the MouseDblClick event (instead of 
the DblClick event), which displays a text box that the user can type in. 
There is probably a better way to do this, but this works OK.
 
#!perl
use strict;
use warnings;
use Win32::GUI qw();
use Win32::GUI::Constants qw(/^WS_/ /^VK_/);
 
my $MW = Win32::GUI::Window->new(
 -name  => 'MW',
 -size  => [350,550],
 -pos  => [250,125],
 -text  => "Listview Example",
 -pushstyle => WS_MINIMIZEBOX | WS_SYSMENU,
);
my $LV_0 = $MW->AddListView(
 -name    => "LV_0",
 -size    => [300,500],
 -pos    => [6,6],
 -fullrowselect  => 1, # Select every colnum's row at the same time
 -hottrack   => 0, # Auto select item , don't click item
 -gridlines   => 1, # Draw the border for list table
 -checkboxes   => 0, # Show the check box on the every row start
 -singlesel   => 1,
 -oneclickactivate => 1, # Change the cursor to onecclick type while on 
the select item
 -editlabel   => 1, # Can be edit
 -visible   => 1,
 -nocolumnheader  => 0, # Hide the column header
);
my($Item,$SubItem);
my $Edit = Win32::GUI::Textfield->new(
 -parent   => $LV_0,
 -name   => 'Edit',
 -visible  => 0,
 -popexstyle  => WS_EX_CLIENTEDGE,
 -onLostFocus => sub {
  #Label isn't changed if user clicks off textfield
  my $self = shift;
  $self->Hide();
  return 1;
 },
 -onKeyDown => sub {
  my($self,$flags,$vkey) = @_;
  #Label is changed on RETURN key
  if($vkey == VK_RETURN){
   my $item = $LV_0->Item($Item);
   if($SubItem){
    my $sub = $item->SubItem($SubItem);
    $sub->Text($self->Text());
   }
   else {
    $item->Text($self->Text());
   }
   $self->Hide();
  }
  #Label isn't changed on ESCAPE key
  elsif($vkey == VK_ESCAPE){
   $self->Hide();
  }
  return 1;
 },
);
$LV_0->InsertColumn(
 -index => 1,
 -width => 150,
 -text => "Column_0",
);
$LV_0->InsertColumn(
 -index => 2,
 -width => 150,
 -text  => "Column_1",
);
for(0..100){
 $LV_0->InsertItem ( -text => [ ( sprintf "index %03d", $_ ), ( sprintf 
"subindex %03d", $_ ) ] );
}
$MW -> Show();
Win32::GUI::Dialog();
exit(0);
sub MW_Terminate{
 -1;
}
sub LV_0_MouseDblClick {
 my($x,$y,$flags) = @_;
 my($item, $subitem, $flag) = $LV_0->SubItemHitTest($x,$y);
 return 1 unless defined $item;
 my @rect;
 if($subitem){
  @rect = $LV_0->GetSubItemRect($item,$subitem);
 }
 else {
  @rect = $LV_0->GetItemRect($item);
 }
 $Edit->Show();
 $Edit->Left($rect[0]);
 $Edit->Top($rect[1]);
 $Edit->Width($rect[2]-$rect[0]);
 $Edit->Height($rect[3]-$rect[1]);
 $Edit->Text($LV_0->GetItemText($item,$subitem));
 $Edit->SelectAll();
 $Edit->SetFocus();
 $Item = $item;
 $SubItem = $subitem;
 return 1;
}

__END__
 
Hope this helps,
 
Kevin.
 
To: perl-win32-gui-users@lists.sourceforge.net
From: miller_c...@sercomm.com
Date: Thu, 19 Nov 2009 16:52:23 +0800
Subject: [perl-win32-gui-users] How to edit ListView subitem ?


Dear All : 

Does any one know how to let the ListView subitem can be edit ? 



Below is my sample code : 

#!perl 
use Win32::GUI ; 

$MW = Win32::GUI::Window -> new(   -name       => 'MW', 
 -size       => [350,550], 
 -pos       =>  [250,125], 
 -text       => "Listview Example", 
 -font       => $font_T_8 , 
                                                       -style      => 
WS_MINIMIZEBOX | WS_SYSMENU, 
                                   ); 
                                                                


$LV_0 = $MW -> AddListView(      -name             => "LV_0", 
                                                                 -size    
=> [300,500], 
                                                                 -pos   => 
[6,6], 
 -fullrowselect    => 1,    # Select every colnum's row at the same time 
                                                                 -hottrack 
        => 0,    # Auto select item , don't click item 
                                 -gridlines        => 1,    # Draw the 
border for list table 
                                  -checkboxes       => 0,    # Show the 
check box on the every row start 
 -singlesel        => 1, 
                                  -oneclickactivate => 1,    # Change the 
cursor to onecclick type while on the select item 
                                  -editlabel        => 1,    # Can be edit 

                                  -visible          => 1,     
 -nocolumnheader   => 0,    # Hide the column header 
                                          ); 



$LV_0 -> InsertColumn( -index => 1, 
                                              -width => 150, 
                                              -text => "Column_0", 
                                          ); 


$LV_0 -> InsertColumn( -index => 2, 
                       -width => 150, 
                       -text  => "Column_1", 
                                         );                    

                                          
#$LV_1 = Win32::GUI::ListView::SubItem -> new( 
#                                              -parent    => $LV_0, 
#                                              -index     => 1, 
#                                              -subindex  => 1,            
 
#                );                                 

for(0..100){ 
     print $LV_0 -> InsertItem ( -text => [ ( sprintf "index %03d", $_ ), 
( sprintf "subindex% 03d", $_ ) ] ), "\n"; 
        } 



$MW -> Show();             
Win32::GUI::Dialog(); 
exit(0); 

sub MW_Terminate{ 

-1; 

} 

sub LV_0_DblClick{ 

print "SelectedItem:", $LV_0 -> SelectedItems(), "\n" ; 
$LV_0 -> EditLabel(  $LV_0 -> SelectedItems() ); 

} 

sub LV_0_BeginLabelEdit{ 

print "BLabelEdit:", "@_", "\n"; 

} 

sub LV_0_EndLabelEdit{ 

print "ELabelEdit:", "@_", "\n"; 

} 

---End-- 

Best Regards 
Miller Chen 
Brought to you exclusively by Windows Live Download new and classic 
emoticon packs at Emoticon World


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to