Share your opinion
WIDGETS GAMBAS
GAMBAS 3 SOFTWARES
TUTORIALS
Library
|
GRIDVIEW - Print gridview
PRINT A GRIDVIEW
Hye, Today we use the Bernard function to print datas inside a gridview. to use this function put in a Button_click event this code : imprimgrid(mygridview) mygridview is your gridview not empty. Here you find the Bernard function : PUBLIC SUB ImprimGrid(grd AS Object) DIM c, r, col, rang, largeur, hauteur, nl, np, i, j, MargeL, MargeB AS Integer DIM page AS Integer[500] DIM p$ AS String DIM coef AS Float 'Printer.resolution = 300 IF Printer.Setup() THEN RETURN coef = CInt((Printer.Resolution / Desktop.Resolution) - 1) MargeL = 16 * coef MargeB = 20 * coef IF Printer.Portrait = TRUE THEN SWAP MargeB, MargeL col = MargeL FOR c = 0 TO grd.Columns.Count - 1 'largeur de la grille largeur += grd.Columns[c].Width NEXT np = 1 FOR r = 0 TO grd.Rows.Count - 1 'Hauteur de la grille et on defini le nombre de pages hauteur += grd.Rows[r].Height IF hauteur * coef > Printer.Height - (64 * coef) THEN page[np] = nl INC np nl = 0 hauteur = 0 ENDIF INC nl NEXT page[np] = nl ' nombre de ligne pour la derniere page( ou la première si il n'y en a qu'une) IF largeur * coef > Printer.Width THEN coef = coef * (Printer.Width / (largeur * (coef * 2))) ' ELSE ' coef = 5 ENDIF FOR i = 1 TO np ' nombre pages col = MargeL rang = MargeB Draw.Begin(Printer) 'Global.HeaderGrid(grd, coef, col, rang) FOR c = 0 TO grd.Columns.Count - 1 'imprimer le header Draw.FillStyle = 2 Draw.FillColor = Color.Gray Draw.Rect(col, rang, grd.Columns[c].Width * coef, MargeB) Draw.Text(grd.Columns[c].Text, col + (2 * coef), rang) col += grd.Columns[c].Width * coef NEXT rang += grd.Rows.Height * coef 'for r=0 to page(i) 'nombre ligne par page 'FOR r = page[i - 1] TO grd.Rows.Count - 1 FOR r = page[i - 1] TO (page[i - 1] + page[i]) - 1 col = MargeL FOR c = 0 TO grd.Columns.Count - 1 'On imprime les grilles Draw.FillColor = grd[r, c].Background IF grd[r, c].Background <> -1 THEN Draw.FillStyle = Fill.Solid ELSE Draw.FillStyle = 0 ENDIF Draw.Rect(col, rang, grd.Columns[c].Width * coef, grd.Rows.Height * coef) col += grd.Columns[c].Width * coef NEXT col = MargeL FOR c = 0 TO grd.Columns.Count - 1 'On imprime le text Draw.Font = grd[r, c].Font Draw.Foreground = grd[r, c].Foreground p$ = "" IF Draw.TextWidth(grd[r, c].Text) > (grd.Columns[c].Width * coef) - (2 * coef) THEN FOR j = 1 TO Len(grd[r, c].Text) IF Draw.TextWidth(p$) < (grd.Columns[c].Width * coef) - (12 * coef) THEN p$ &= Mid$(grd[r, c].Text, j, 1) ENDIF NEXT ELSE p$ = grd[r, c].Text ENDIF Draw.Text(p$, col + (2 * coef), rang, (grd.Columns[c].Width * coef) - (2 * coef), grd.Rows.Height * coef, grd[r, c].Alignment) col += grd.Columns[c].Width * coef NEXT rang += grd.Rows.Height * coef NEXT p$ = "_ " & Trim(Str$(i)) & " _" Draw.Text(p$, (Printer.Width - Draw.TextWidth(p$)) / 2, Printer.Height - (48 * coef)) Draw.End NEXT END Thanks to Bernard for his contribution. Creation date : 21/05/2010 @ 16:36 Reactions to this article
| QUICK MENU
SEARCH
LANGUAGE
COMPONENTS
Other
LANGUAGE
Where, who?
VISITS
visitors visitors online ARCHIVES GAMBAS 1/2
|