[C# 2.0] Utilisation d'un DataGridView conçu graphiquement avec un dataSet.Fill
Bonjour,
Je ne sais pas comment faire :
J'ai construit une DataGridView en utilisant le concepteur graphique (facile et pratique il est réutilisé par beaucoup d'autres applications dans l'état).
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
//
// dataGrid1
//
this.dataGrid1.AllowUserToAddRows = false;
this.dataGrid1.AllowUserToDeleteRows = false;
this.dataGrid1.Blocked = false;
this.dataGrid1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.dataGrid1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colGroupeValide,
this.colGroups});
this.dataGrid1.Location = new System.Drawing.Point(13, 70);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.RowHeadersWidth = 20;
this.dataGrid1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.dataGrid1.Size = new System.Drawing.Size(373, 157);
this.dataGrid1.TabIndex = 23;
//
// colGroupeValide
//
this.colGroupeValide.Frozen = true;
this.colGroupeValide.HeaderText = "";
this.colGroupeValide.MinimumWidth = 30;
this.colGroupeValide.Name = "Selected";
this.colGroupeValide.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colGroupeValide.Width = 30;
//
// colGroups
//
this.colGroups.HeaderText = "Nom des groupes";
this.colGroups.MinimumWidth = 300;
this.colGroups.Name = "NomGroupe";
this.colGroups.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colGroups.Width = 300; |
avec la requete SQL qui retourne (elle aussi est utilisée à divers endroits et on utilise pas les mêmes colonnes en fonction d'où elle est utilisée) :
Code:
1 2 3 4 5 6 7 8 9
|
begin
FOR
SELECT GROUPES.ID_GROUPES, GROUPES.NOM, 1
FROM GROUPES
ORDER BY NOM
INTO :IdGroupe, :NomGroupe, :Selected
DO SUSPEND;
end |
Lors de la sélection des données dans la DB, j'utilise le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
FbCommand cde = baseData.CreateCommand("DONNEES_GROUPE_SELECT", CommandType.StoredProcedure);
FbDataAdapter datap = new FbDataAdapter(cde);
try
{
this.dat.Rows.Clear();
if (baseData.OpenConnection(baseData.SqlConnection))
{
datap.Fill(this.dat);
baseData.SqlConnection.Close();
}
}
catch
{
return null;
}
// retourne les valeurs
return dat; |
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
dat.Clear();
this.colGroups.DataSource = dat;
this.colGroups.DisplayMember = "NomGroupe";
this.colGroups.MaxDropDownItems = 25;
this.dataGrid1.DataError += new DataGridViewDataErrorEventHandler(dataGrid1_DataError);
this.dataGrid1.DataSource = dat;
this.dataGrid1.Columns[0].DataPropertyName = "Selected";
this.dataGrid1.Columns[1].DataPropertyName = "NomGroupe";
this.dataGrid1.Refresh();
this.dataGrid1.Enabled = true; |
le problème c'est que si dans mon dataGrid j'ai un nombre inférieur de colonnes à celui de la requete SELECT (et ici c'est le cas), de toute façon il me rajoute les colonnes du SELECT après les colonnes déjà présentes dans le DataGrid.
CA me prend un peu la tete et je ne vois pas comment faire proprement.
Un petit conseil ?
Merci.