From: Thomas, T. B <tim...@lm...> - 2001-02-15 16:59:49
|
Someone else has written a win32::Gui program to do just what you are = trying to do. I don't seem to have the code anymore. Maybe they can post it = again, or you can search the archives. Here's a piece of code I just wrote that gets all the data, including = the image, from a listview, it puts it into a hash. I used this with the column sort routine that has been floating around, = by Jonathan Southwick [jso...@al...]. I am still working out the bugs, but this section of code should help you. # you must already have $totalcols (the # of columns in your listview) # I don't think there is a way to pull this from the object. %data=3D(); $rows=3D$ListView->Count(); for $i(0..$rows-1) { $row=3D""; my %result=3D$ListView->GetItem($i,0); $image=3D$result{-image}; for $j(0..$totalcols-1) { my %result=3D$ListView->GetItem($i,$j); $text=3D$result{-text}; $row.=3D",$text"; } $data{$i}=3D"$image$row"; #Win32::MsgBox("data($i)=3D$image$row\n"); } ------------------------------------------------------------------------= ---- --------------------- Tim Thomas Unix Systems Administrator Lockheed Martin EIS =B7 Denver Data Center 303-430-2281 mailto:tim...@lm... ------------------------------------------------------------------------= ---- --------------------- -----Original Message----- From: Michael Solomon [mailto:MSo...@3s...] Sent: Thursday, February 15, 2001 5:19 AM To: Perl Gui (E-mail) Subject: [perl-win32-gui-users] get value from list I am querying a database and putting the output into a listview What I would like to next is to click on an item in the list and then drilldown into the data base The question is how can I return the value from a List I am fairly new at using Win32::GUI and apologise if this is a stupid question. Should I be using a different type than listview and if so what should = I be using? use strict; use Socket; use Win32::GUI; use Win32::ODBC; #set variables my (%Data, %new, $result, $Window, $width); my $Dir =3D "//neptune/tech_dept/databases"; my $DBase =3D "asset.mdb"; my $DriverType =3D "Microsoft Access Driver (*.mdb)"; my $Desc =3D "Description=3DThe Win32::ODBC Test DSN for = Perl"; my $DSN =3D "tmpdsn"; $Window =3D new GUI::Window( -name =3D> "Window", -text =3D> "Win32::GUI::ListView test", -width =3D> 350, -height =3D> 500, -left =3D> 100, -top =3D> 100, ); $Window->AddListView( -name =3D> "ListView", -left =3D> 10, -top =3D> 10, -width =3D> 330, -height =3D> 383, -style =3D> WS_VISIBLE | 1, -gridlines =3D> 1, ); $width =3D $Window->ListView->ScaleWidth; $Window->ListView->InsertColumn( -index =3D> 0, -width =3D> $width/2, -text =3D> "Asset No", ); $Window->ListView->InsertColumn( -index =3D> 1, -width =3D> $width/2, -text =3D> "IP Address", ); $Window->AddRadioButton( -name =3D> "Radio1", -left =3D> 8, -top =3D> 410, -text =3D> "192 Network ", -tabstop =3D> 1, ); $Window->AddRadioButton( -name =3D> "Radio2", -left =3D> 8, -top =3D> 430, -text =3D> "212 XTML ", -tabstop =3D> 1, ); $Window->AddRadioButton( -name =3D> "Radio3", -left =3D> 8, -top =3D> 450, -text =3D> "212 EasyNet ", -tabstop =3D> 1, ); #$Window->ListView->TextColor(hex("0000FF")); $Window->Show(); $Window->Dialog(); sub MAIN { #set up dsn Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, $DriverType, = ("DSN=3D$DSN", "Description=3DThe Win32 ODBC Test DSN for Perl", "DBQ=3D$Dir\\$DBase", "DEFAULTDIR=3D$Dir", "UID=3D", "PWD=3D")); #open connection as $0 my $cO =3D new Win32::ODBC($DSN); #run sql $cO->Sql("SELECT assetid, ipaddress FROM ip_address where = ipaddress like '${result}%'"); #reset new %new =3D (); # Fetch the next rowset while($cO->FetchRow()){ %Data =3D $cO->DataHash(); #convert to binary $new{inet_aton($Data{ipaddress})} =3D "$Data{assetid},$Data{ipaddress}"; } #close database $cO->Close(); #remove tempdsn Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, $DriverType, = "DSN=3D$DSN"); #clear items $Window->ListView->Clear(); =20 foreach (sort keys %new) { my ($asset, $ip ) =3D split(",",$new{$_}); $Window->ListView->InsertItem(-text =3D> [ "$asset", = "$ip" ] ); }; } sub MAIN1 { #clear items $Window->ListView->Clear(); =20 foreach (sort numeric values %new) { my ($asset, $ip ) =3D split(",",$_); $Window->ListView->InsertItem(-text =3D> [ "$asset", = "$ip" ] ); }; } sub numeric { $a <=3D> $b }; sub Radio1_Click { if($Window->Radio1->Checked()) { $result =3D "192"; &MAIN; } elsif($Window->Radio2->Checked()) { $result =3D "212.88"; &MAIN; } elsif($Window->Radio3->Checked()) { $result =3D "212.74"; &MAIN; } } sub Radio2_Click { Radio1_Click(); } sub Radio3_Click { Radio1_Click(); } sub ListView_ColumnClick { my $column =3D shift; if ($result ne "" ) { if ( $column =3D=3D 1 ) {&MAIN;} if ( $column =3D=3D 0 ) {&MAIN1;} } =20 } __END__ Regards Mike Solomon Technical Manager Work 01582 831125 Mobile 07941 537 172 email mso...@3s... =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =3D=3D=3D=3D=3D=3D Important: Any views or opinions expressed by the sender do not = necessarily represent those of the 3s Group. This e-mail and any attachment(s) are intended for the above named only and may be confidential. If you = are not the named recipient please notify us immediately. You must not copy or disclose the contents to any third party. Internet e-mail is not a fully secure communications medium. Please = take this into account when sending e-mail to us. Any attachment(s) to this e-mail are believed to be free from virus, = but it is the responsibility of the recipient to make all the necessary virus checks.=20 www.3s-group.com =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D |