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