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
_________________________________________________________________
Download new and classic emoticon packs at Emoticon World Brought to you
exclusively by Windows Live
http://windowslive.ninemsn.com.au/emoticon.aspx?
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
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/