From: Mattia B. <mat...@li...> - 2003-12-06 21:49:38
|
Il Tue, 2 Dec 2003 10:23:17 +0100 Thomas Klausner <do...@zs...> ha scritto: Hello, > I'm currently developing a small application for in-house use. > Basically, > it's a database front end, i.e. users should be able to view, > insert, edit, > delete some data. > > I got some basic stuff working, but I'm wondering if there is a > "standard" > way of generating a Wx::Grid from database data. No, there isn't. > Here's what I'm doing: > in MyApp::new, I set up a panel, and generate a grid > > my $grid=Wx::Grid->new($panel,-1,wxDefaultPosition,[750,300]); > > I fetch stuff from a database (using Class::DBI): > > my @ks=ZCont::DB::Kostenstelle->retrieve_all; > my $rows=@ks || 1; > $grid->CreateGrid($rows,7); > > foreach my $kostenstelle (@ks) { > my $row=0; > my $col=0; > foreach(qw(kostenstelle titel beginn ende leitung overhead > budget)) { > $grid->SetCellValue($row,$col,$kostenstelle->$_); > $col++; > } > $row++; > } > > (If you're not familiar with Class::DBI : @ks is an array containing > objects. Each object as accessors which correlate to a column) > > This is working as expected, but there might be some better ways to > set up a > Grid ? Using a custom Wx::GridTable (there is a xample in the wxPerl demo) might be a good idea. > Additionally, some more questions (I'm coming from a Web > background..): > > Say I've got 1000 rows in a table, but only want to display 100 in > a Grid, > would I: > * fetch all 1000 columns and add/delete them from the Grid if the > user pages > up/down > > * fetch only 100, delete them when they disappear from the screen, > and fetch > new ones if they are needed (this is what I would do in a Web > Environment, > which is stateless) > > * something completly different? It depends. I think that, for a GUI application, it is better to display all 1000 rows at once and let the user scroll them using the scrollbars. If you use a custom Wx::GridTable you can fetch the rows on demand (thus avoiding fetching a large amount of data the user might not need/look at). HTH Mattia P.S.: I think that a generic "Database Grid" might be a good candidate for CPAN. if you feel like releasing it |