DataGrid

cs_latatia Messages postés 15 Date d'inscription mardi 2 mars 2004 Statut Membre Dernière intervention 22 mars 2004 - 19 mars 2004 à 11:09
cs_Botanique Messages postés 113 Date d'inscription vendredi 21 janvier 2005 Statut Membre Dernière intervention 6 mars 2008 - 13 sept. 2005 à 19:59
J'aimerais savoir comment fait on four ajouter des colonnes, mettre les entête, et mettre les valeurs à partir d'un recordset dans une DataGrid et enfin deuxième question comment fait on à partir du choix que l'on aura fait dans une comboBox afficher le résultat dans une datagrid.

Merci d'avance

3 réponses

gaa179 Messages postés 361 Date d'inscription mercredi 21 mai 2003 Statut Membre Dernière intervention 12 novembre 2009 2
19 mars 2004 à 13:50
Salut,

Pour lier un datagrid avec un combobox, place un filtre correspondant à la valeur de ton Combobox sur le recordset de ton datagrid

Set datagrid1.Datasource = rs
rs.Filter="Field1=" & Combo1.ListIndex

Voici un exempe concerant entête, format, largeur, field source des colonnes

With DataGrid1
Set .DataSource = RsArticle
.Visible = True
NbCol = .Columns.Count
.Caption = ViewGroup.SelectedItem

'Effacement des colonnes
For i = NbCol - 1 To 1 Step -1
.Columns.Remove (i)
Next i

'Creation des colonnes
For i = 0 To 4 + NbCar
.Columns.Add (i)
Next i

'Columns header
.Columns(0).Caption = "Quantite"
.Columns(0).Width = 800
.Columns(0).Locked = True
.Columns(1).Caption = "En commande"
.Columns(1).Width = 1200
.Columns(1).Locked = True
.Columns(2).Caption = "Description"
.Columns(2).Width = 2000
For i = 3 To 2 + NbCar
.Columns(i).Caption = Car(i - 3)
.Columns(i).Width = WCar(i - 3)
Next i
PtCol = NbCar + 3
.Columns(PtCol).Caption = "Prix d'achat HTVA"
.Columns(PtCol).Width = 1500
.Columns(PtCol + 1).Caption = "Prix de vente HTVA"
.Columns(PtCol + 1).Width = 1500
.Columns(PtCol + 2).Caption = "Fournisseur"
.Columns(PtCol + 2).Width = 1500

'Columns data
If Not RsArticle.EOF Then
.Columns(0).DataField = "Quantite"
.Columns(1).DataField = "Cmd"
'.Columns(1).Locked = True
Set .Columns(1).DataFormat = fmtBooleanData
.Columns(2).DataField = "Libelle_FR"
.Columns(2).Locked = True
PtCol = 3
If NbCar > 0 Then
For i = 1 To NbCar
.Columns(i + 2).DataField = "Caract" & i
.Columns(i + 2).Locked = True
Next i
PtCol = 3 + NbCar
End If
.Columns(PtCol).DataField = "Prix_achat"
.Columns(PtCol).Locked = True
.Columns(PtCol).DataFormat.Format = "#,##0.0000 €"
.Columns(PtCol + 1).DataField = "Prix_Unit"
.Columns(PtCol + 1).Locked = True
.Columns(PtCol + 1).DataFormat.Format = "#,##0.0000€"
.Columns(PtCol + 2).DataField = "Nom"
.Columns(PtCol + 2).Locked = True
End If
.Rebind
.Refresh

'Lock la premiere colonne si nécessaire
If InStr(1, MDIMain.Tag, "OutArt", vbTextCompare) > 0 Then DataGrid1.Columns(0).Locked = True

'Ajuste la dimension des colonnes
'.Columns(1).Width

Me.Refresh
0
cs_latatia Messages postés 15 Date d'inscription mardi 2 mars 2004 Statut Membre Dernière intervention 22 mars 2004
22 mars 2004 à 09:44
J'aimerais savoir si il est possible de lier une msgFlexGrid à une combo si oui comment

merci
0
cs_Botanique Messages postés 113 Date d'inscription vendredi 21 janvier 2005 Statut Membre Dernière intervention 6 mars 2008
13 sept. 2005 à 19:59
Bonjour,
ta réponse m'intéresse beaucoup mais quand je tape DataGrid1.columns(0).width = 1, j'ai une erreure.
La propriété columns de DataGrid n'existe pas.

Comment faire?

Botanique
0
Rejoignez-nous