Utiliser les tableview
Rédigé par spheris
Aucun commentaire
Pour utiliser la tableview, nous allons définir l 'objet par la commande :
Dim TB as tableview
TB=new tableview(me)
Nous definissons le nombre de lignes et colonnes :
TB.columns.count=5              '5 colonnes définies
TB.rows.count=21                   '20 ligne définies
Définissons les dimensions des lignes et colonnes
TB.columns.width=100
TB.rows.height=20
Définissons les entêtes de chaque colonne :
TB.header=1 '0 -> Aucune     1 -> horizontal     2 -> vertical     3 -> les deux
TB.columns[0].title= Titre
TB.columns[0].width=50
TB.columns[1].title= Client
TB.columns[2].title= Facture
TB.columns[2].width=40
TB.columns[3].title= Etranger
TB.columns[3].width=50
TB.columns[4].title= type
TB.columns[4].width=50
Définissons la couleur du texte :
 im Linea as integer, SwColor as boolean, Rec as result, Sql as string, Cn as connection
Sql= select * from clientes order by codigo
Rec=Cn.exec(sql)
TB.rows.count=Rec.count+1
do while Rec.available
  TB[linea, 0].text = Rec!Codigo
  TB[linea, 0].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 0].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 0].Alignment = 2
  TB[linea, 1].text = Rec!nombre
  TB[linea, 1].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 1].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 1].Alignment = 1
  TB[linea, 2].text = Rec!dir
  TB[linea, 2].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 2].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 2].Alignment = 1
  Rec.movenext
  Linea+=1
  SwColor=NOT swcolor 'inversion de la couleur
loop
Edition des cellules :
sub TB_change()
dim Tabla as new string[]
tabla.add( opcion 1 )
tabla.add( opcion 2 )
if TB.columnat=2 then
   TB.edit(tabla,true) 'para actualizar la celda se mostrará un combo con las opciones descritas
                                 ' la opción TRUE de readonly indica que solo se podrá elegir del combo.
else
  TB.edit 'activar modo edición en celda en textbox
endif
end
sauvegarde de la table dans la base de données :
sub TB_save(Row AS Integer, Column AS Integer, Value AS String)
Dim Sql as string
Sql= update clientes set codigo= & TB[TB.row,0].text & ', nombre) ' & TB[TB.row,1].text & ', direccion= ' & TB[TB.row,2].text & '
Cn.exec(sql)
end
Dim TB as tableview
TB=new tableview(me)
Nous definissons le nombre de lignes et colonnes :
TB.columns.count=5              '5 colonnes définies
TB.rows.count=21                   '20 ligne définies
Définissons les dimensions des lignes et colonnes
TB.columns.width=100
TB.rows.height=20
Définissons les entêtes de chaque colonne :
TB.header=1 '0 -> Aucune     1 -> horizontal     2 -> vertical     3 -> les deux
TB.columns[0].title= Titre
TB.columns[0].width=50
TB.columns[1].title= Client
TB.columns[2].title= Facture
TB.columns[2].width=40
TB.columns[3].title= Etranger
TB.columns[3].width=50
TB.columns[4].title= type
TB.columns[4].width=50
Définissons la couleur du texte :
 im Linea as integer, SwColor as boolean, Rec as result, Sql as string, Cn as connection
Sql= select * from clientes order by codigo
Rec=Cn.exec(sql)
TB.rows.count=Rec.count+1
do while Rec.available
  TB[linea, 0].text = Rec!Codigo
  TB[linea, 0].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 0].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 0].Alignment = 2
  TB[linea, 1].text = Rec!nombre
  TB[linea, 1].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 1].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 1].Alignment = 1
  TB[linea, 2].text = Rec!dir
  TB[linea, 2].Background = IIf(SwColor, COLOR.White, COLOR.Black)
  TB[linea, 2].Foreground = IIf(SwColor, COLOR.Black, COLOR.White)
  TB[linea, 2].Alignment = 1
  Rec.movenext
  Linea+=1
  SwColor=NOT swcolor 'inversion de la couleur
loop
Edition des cellules :
sub TB_change()
dim Tabla as new string[]
tabla.add( opcion 1 )
tabla.add( opcion 2 )
if TB.columnat=2 then
   TB.edit(tabla,true) 'para actualizar la celda se mostrará un combo con las opciones descritas
                                 ' la opción TRUE de readonly indica que solo se podrá elegir del combo.
else
  TB.edit 'activar modo edición en celda en textbox
endif
end
sauvegarde de la table dans la base de données :
sub TB_save(Row AS Integer, Column AS Integer, Value AS String)
Dim Sql as string
Sql= update clientes set codigo= & TB[TB.row,0].text & ', nombre) ' & TB[TB.row,1].text & ', direccion= ' & TB[TB.row,2].text & '
Cn.exec(sql)
end