Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Column headers
Message
 
À
29/08/2005 22:12:09
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01045005
Message ID:
01045009
Vues:
22
Hilmar,
If you set a break point in your code and view the dataset or datatable in the Watch window you will see that the DataColumn.Caption property is set correctly ( I had to test your code to be 100% sure).
I think the reason you think the DataColumn.Caption property is not set is because the grid's column header is set to the column name rather than the column caption (correct me if I am wrong).
Below is some code I use to get more control over the grid's columns:
// Add datasource to the grid
this.dataGrid1.DataSource = this.oDataSet.CollectionTable;


System.Windows.Forms.DataGridTableStyle style = new System.Windows.Forms.DataGridTableStyle();
			
style.MappingName = this.oDataSet.CollectionTable.ToString();

System.Windows.Forms.DataGridTextBoxColumn fld0 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld0.HeaderText = "Node";
fld0.MappingName = this.oDataSet.CollectionTable.colNodeNumberColumn.ToString();
fld0.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld1 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld1.HeaderText = "Generation";
fld1.MappingName = this.oDataSet.CollectionTable.colControlGenTypeColumn.ToString();
fld1.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld2 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld2.HeaderText = "Ctrl Time";
fld2.MappingName = this.oDataSet.CollectionTable.colControlDateTimeColumn.ToString();
fld2.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld3 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld3.HeaderText = "Ctrl Cycles";
fld3.MappingName = this.oDataSet.CollectionTable.colTotalCyclesColumn.ToString();
fld3.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld4 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld4.HeaderText = "# IR Download";
fld4.MappingName = this.oDataSet.CollectionTable.colTotalIrDownloadsColumn.ToString();
fld4.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld5 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld5.HeaderText = "Last IR Download";
fld5.MappingName = this.oDataSet.CollectionTable.colLastIrDownloadColumn.ToString();
fld5.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld6 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld6.HeaderText = "# Bad IR";
fld6.MappingName = this.oDataSet.CollectionTable.colTotalBadIrDownloadsColumn.ToString();
fld6.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld7 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld7.HeaderText = "Last Bad IR";
fld7.MappingName = this.oDataSet.CollectionTable.colLastBadIrDownloadColumn.ToString();
fld7.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld8 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld8.HeaderText = "# NW Download";
fld8.MappingName = this.oDataSet.CollectionTable.colTotalNwDownloadsColumn.ToString();
fld8.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld9 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld9.HeaderText = "Last NW Download";
fld9.MappingName = this.oDataSet.CollectionTable.colLastNwDownloadColumn.ToString();
fld9.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld10 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld10.HeaderText = "# Bad NW";
fld10.MappingName = this.oDataSet.CollectionTable.colTotalBadNwDownloadsColumn.ToString();
fld10.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld11 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld11.HeaderText = "Last Bad NW";
fld11.MappingName = this.oDataSet.CollectionTable.colLastBadNwDownloadColumn.ToString();
fld11.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld12 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld12.HeaderText = "Crtl Version";
fld12.MappingName = this.oDataSet.CollectionTable.colControlSoftwareVersionColumn.ToString();
fld12.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld13 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld13.HeaderText = "Access Panel";
fld13.MappingName = this.oDataSet.CollectionTable.colAccessPanelOpeningsColumn.ToString();
fld13.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld14 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld14.HeaderText = "Coin Vault";
fld14.MappingName = this.oDataSet.CollectionTable.colCoinVaultOpeningsColumn.ToString();
fld14.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld15 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld15.HeaderText = "# Power Fails";
fld15.MappingName = this.oDataSet.CollectionTable.colTotalPowerFailsColumn.ToString();
fld15.Width = 55;

System.Windows.Forms.DataGridTextBoxColumn fld16 = new System.Windows.Forms.DataGridTextBoxColumn(); 
fld16.HeaderText = "Last Power Fail";
fld16.MappingName = this.oDataSet.CollectionTable.colLastPowerFailColumn.ToString();
fld16.Width = 55;


style.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {fld0, fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8, fld9, fld10, fld11, fld12, fld13, fld14, fld15, fld16 });

this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(style);
This is some old code from an old app but the grid looks good and it worked the way I wanted it when I wrote the code:) Check out the M$ docs for TableStyles

Hope is helps and that I understand your issue.

Einar
>While creating a grid programmatically (not based on a table), I am having trouble setting the column headers.
>
>Here is part of my code:
>
>
>// Instantiate objects
>Ds = new DataSet();
>Dt = new DataTable();
>for (i=0; i<numColumnas; i++)
>{
>  Dc = new DataColumn();
>  Dc.ColumnName = "Col_" + (i).ToString();
>  Dc.Caption = "x " + (i).ToString();
>  Dc.DataType = System.Type.GetType("System.String");
>  Dt.Columns.Add(Dc);
>  ...
>}
>// Add tables to DataSet
>Ds.Tables.Add(Dt);
>
>// Assign to grid
>dgLista.DataSource = Ds;
>dgLista.DataMember = Ds.Tables[0].TableName;
>...
>
>
>The trouble is, the caption remains the same as the column name, for example, "Col_1", when I expect "x 1".
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform