|
From: Erick J. B. <er...@e-...> - 2001-02-14 19:16:30
|
I'm trying to test if any items have been selected in a
listview with a button event and I have used the -singlesel
option on the listview. So, therefore, if the user clicks
the button without selecting anything, I would like to have
a MsgBox, else take the value of the the choosen selection
and do some computation.
$MainWin->AddListView(
-name => "ListView",
-pos => [85, 100],
-size => [$MainWin->ScaleWidth-160,
$MainWin->ScaleHeight-170],
-style => WS_CHILD | WS_VISIBLE | 1 |
WS_HSCROLL | WS_VSCROLL,
-fullrowselect => -1,
-gridlines => 0,
-hottrack => 0,
-visible => 0,
-view => 1,
-tabstop => 4,
-singlesel => 1,
);
$width = $MainWin->ListView->ScaleWidth;
$MainWin->ListView->InsertColumn(
-index => 0,
-subitem => 0,
-width => $width-15,
-text => "Column",
);
for (sort keys %SomeHash) {
$MainWin->ListView->InsertItem(-text=>[$_]);
}
$MainWin->AddButton(
-name => "Button",
-text => "&Ok",
-pos => [347, 350],
-height => 20,
);
sub Button_Click {
my @index = $MainWin->ListView->SelectedItems();
if (@index[0] >= 0) { #I need the zero because of the
zero-based index
#do something...
} else {
Win32::MsgBox(...);
}
When "Button" is pressed it always falls through the if
statement. Even in the case of no selection it falls through
because @index[0], in this case, is undef. I know undef is
the same as 0, but how could I get around this?
erick
never stop questioning
www.jeb.ca
|
|
From: Jeremy B. <sco...@ya...> - 2001-02-14 22:03:38
|
Well, I don't know if this will actually fix your
problem, but you should definitely be using
"$index[0]" instead of "@index[0]".
Just my 2 cents,
jb
--- "Erick J. Bourgeois" <er...@e-...> wrote:
> I'm trying to test if any items have been selected
> in a
> listview with a button event and I have used the
> -singlesel
> option on the listview. So, therefore, if the user
> clicks
> the button without selecting anything, I would like
> to have
> a MsgBox, else take the value of the the choosen
> selection
> and do some computation.
>
> $MainWin->AddListView(
> -name => "ListView",
> -pos => [85, 100],
> -size => [$MainWin->ScaleWidth-160,
> $MainWin->ScaleHeight-170],
> -style => WS_CHILD | WS_VISIBLE | 1
> |
> WS_HSCROLL | WS_VSCROLL,
> -fullrowselect => -1,
> -gridlines => 0,
> -hottrack => 0,
> -visible => 0,
> -view => 1,
> -tabstop => 4,
> -singlesel => 1,
> );
> $width = $MainWin->ListView->ScaleWidth;
> $MainWin->ListView->InsertColumn(
> -index => 0,
> -subitem => 0,
> -width => $width-15,
> -text => "Column",
> );
> for (sort keys %SomeHash) {
> $MainWin->ListView->InsertItem(-text=>[$_]);
> }
> $MainWin->AddButton(
> -name => "Button",
> -text => "&Ok",
> -pos => [347, 350],
> -height => 20,
> );
>
> sub Button_Click {
> my @index = $MainWin->ListView->SelectedItems();
> if (@index[0] >= 0) { #I need the zero because
> of the
> zero-based index
> #do something...
> } else {
> Win32::MsgBox(...);
> }
>
> When "Button" is pressed it always falls through the
> if
> statement. Even in the case of no selection it falls
> through
> because @index[0], in this case, is undef. I know
> undef is
> the same as 0, but how could I get around this?
>
> erick
> never stop questioning
> www.jeb.ca
>
>
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Per...@li...
>
http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/
|
|
From: Erick J. B. <er...@e-...> - 2001-02-14 23:21:47
|
Jeremy, sorry what I gave was a typo, I did indeed have
$Index[0] (Cutting and pasting error :) ). It should look
like this:
$MainWin->AddListView(
-name => "ListView",
-pos => [85, 100],
-size =>
[$MainWin->ScaleWidth-160,$MainWin->ScaleHeight-170],
-style => WS_CHILD | WS_VISIBLE | 1
|WS_HSCROLL | WS_VSCROLL,
-fullrowselect => -1,
-gridlines => 0,
-hottrack => 0,
-visible => 0,
-view => 1,
-tabstop => 4,
-singlesel => 1,
);
$width = $MainWin->ListView->ScaleWidth;
$MainWin->ListView->InsertColumn(
-index => 0,
-subitem => 0,
-width => $width-15,
-text => "Column",
);
for (sort keys %SomeHash) {
$MainWin->ListView->InsertItem(-text=>[$_]);
}
$MainWin->AddButton(
-name => "Button",
-text => "&Ok",
-pos => [347, 350],
-height => 20,
);
sub Button_Click {
my @index = $MainWin->ListView->SelectedItems();
if ($index[0] >= 0) { #I need the zero because of the
zero-based index
#do something...
} else {
Win32::MsgBox(...);
}
Any more ideas are more than welcome.
erick
never stop questioning
www.jeb.ca
----- Original Message -----
From: Jeremy Blonde <sco...@ya...>
To: <per...@li...>
Sent: Wednesday, February 14, 2001 11:04 PM
Subject: Re: [perl-win32-gui-users] SelectedItems method
> Well, I don't know if this will actually fix your
> problem, but you should definitely be using
> "$index[0]" instead of "@index[0]".
>
> Just my 2 cents,
> jb
>
|
|
From: Aldo C. <da...@pe...> - 2001-02-15 10:12:41
|
Erick J. Bourgeois wrote:
> [...]
> When "Button" is pressed it always falls through the if
> statement. Even in the case of no selection it falls through
> because @index[0], in this case, is undef. I know undef is
> the same as 0, but how could I get around this?
UNDEF IS NOT THE SAME AS 0! this is, speaking in perl terms,
an heresy and you shall be punished with eternal fire ;-)
undef is *evaluated* as 0 in numerical context and as "" in
string context, but is not 'the same'.
perl has a defined() function to check if something is
'not undef', including 0 and "". your if statement should
look like this:
if( defined( $index[0] ) ) {
cheers,
Aldo
__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;
|
|
From: Erick J. B. <er...@e-...> - 2001-02-15 11:14:28
|
> UNDEF IS NOT THE SAME AS 0! this is, speaking in perl terms, > an heresy and you shall be punished with eternal fire ;-) Mia colpa, mia colpa...won't happen again :) erick never stop questioning www.jeb.ca |