Hiya tivolinewbie,
Sorry, no guru but I have been using Laurent's Grid control since he first
mentioned it at the beginning of May, and have found it absolutely
excellent. In part of a program I have written, I do a similar thing with
populating the grid from an array.
First the array is constructed fairly simply while processing a file, so
that each $value contains successive cell or column data, and $processedline
is the row (with each cell seperated by the pipe), as below:
$processedline = "$value1|$value2|$value3| etc..";
push(@procdata, $processedline);
While processing the data I keep a count of how many lines are processed. In
your case, if you make a call to retrieve the number of rows returned in
your query and set this value as the count - $processcount.
# =============================================================
# Create Grid control
$gridProcDataView = new Win32::GUI::Grid (
-parent => $ResultWindow,
-name => "gridProcDataView",
-left => 0,
-top => 246,
-width => 590,
-height => 174,
-vscroll => 1,
-hscroll => 1,
-fixedrows => 1,
-columns => 10,
-editable => 0,
) or die "can't create new Grid for - gridProcDataView.";
# Hmmm doesn't appear to work without this.
$gridProcDataView->Resize (590, 174);
# =============== START OF PROCESSED GRID =====================
$col_index = 0;
$row_index = 0;
# First set the number of rows (from functions - &lineREPORTER)
$ResultWindow->gridProcDataView->SetRows($processcount + 1);
# Label 'Processed Data'
$ResultWindow->lblProcOPFileLocnP->Text("$outfile");
print "PROC_GRID ROWS - $processcount\n" if $DEBUG;
# Populate Header columns
$ResultWindow->gridProcDataView->SetCellText($row_index, 0,"Calling
Number");
$ResultWindow->gridProcDataView->SetCellText($row_index, 1,"Call Date");
$ResultWindow->gridProcDataView->SetCellText($row_index, 2,"Call Time");
$ResultWindow->gridProcDataView->SetCellText($row_index, 3,"Called Number");
$ResultWindow->gridProcDataView->SetCellText($row_index, 4,"Number Desc");
$ResultWindow->gridProcDataView->SetCellText($row_index, 5,"Duration");
$ResultWindow->gridProcDataView->SetCellText($row_index, 6,"Origin of
Call");
$ResultWindow->gridProcDataView->SetCellText($row_index, 7,"Destination of
Call");
$ResultWindow->gridProcDataView->SetCellText($row_index, 8,"Cost");
$ResultWindow->gridProcDataView->SetCellText($row_index, 9,"Decode Spec");
$ResultWindow->gridProcDataView->SetHeaderSort();
foreach $proclines (@procdata) {
# Skip blank lines
if ($proclines =~ /^$/) {
next;
}
$row_index++;
# Split line into fields
@proclines2fields = split /\|/, $proclines;
# now fill the cells
for ($col_index = 0; $col_index <= 9; $col_index++) {
$ResultWindow->gridProcDataView->SetCellText($row_index, $col_index,
$proclines2fields[$col_index]);
}
}
# Resize Grid Cell
$ResultWindow->gridProcDataView->AutoSize();
Lastly if you are going to perform another query, you will need to empty the
grid. I haven't quite got this yet. But the code below at least empties it,
but it does not refresh the Grid if say a column was highlighted. Perhaps
someone else knows how to re-set it completely.
# Reset Grid
$ResultWindow->gridProcDataView->SetRows(1);
$ResultWindow->gridProcDataView->Refresh();
Hope this helps
rgds
Chris Wearn