I have added a TableStyle and GridColumnStyles to the properties of the
datagrid.
This has generated the following code in InitializeComponent:
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGrid1.TableStyles.Add(this.dataGridTableStyle1);
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn1);
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn2);
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn3);
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn4);
this.dataGridTextBoxColumn1.HeaderText = "ID";
this.dataGridTextBoxColumn1.NullText = "(null)";
this.dataGridTextBoxColumn1.Width = 0;
this.dataGridTextBoxColumn2.HeaderText = "Priority";
this.dataGridTextBoxColumn2.NullText = "(null)";
this.dataGridTextBoxColumn2.Width = 100;
etc.
Unfortunately this doesnt work - the column headings have the names of the
columns from the table in the dataset.
Any help would be appreciated
Thanks
John
To wrap up the issue, shortly, the following points IN CODE, worked for me
(IN THE LISTED ORDER) :
1. Setting the RowHeaders of the datagrid visible
2. Creating a new DataGridTableStyle
3. NB. make sure the MappingName for the new DataGridTableStyle IS
the same as the TableName of the DataTable
4. Creating and adding DataGridColumnStyles to the new DataGridTableStyle
5. Adding the new DataGridTableStyle to the TableStyles of the DataGrid
An abbreviated, rewritten sample wrap up code is also attached, enjoy:
dtgrid.RowHeadersVisible=true;
DataGridTableStyle dgtsEquipment = new DataGridTableStyle();
dgtsEquipment.MappingName="tblEquipment";
DataGridColumnStyle dgcsEquipmentID = new DataGridTextBoxColumn();
dgcsEquipmentID.MappingName = "EquipmentID";
dgcsEquipmentID.HeaderText = "EquipmentID";
dgcsEquipmentID.Width = 0;
dgtsEquipment.GridColumnStyles.Add(dgcsEquipmentID);
DataGridColumnStyle dgcsDescription = new DataGridTextBoxColumn();
dgcsDescription.MappingName="Description";
dgcsDescription.HeaderText="Description";
dgcsDescription.Width=100;
dgtsEquipment.GridColumnStyles.Add(dgcsDescription);
dtgrid.TableStyles.Add(dgtsEquipment);
You just edit the .HeaderText, and you should be OK :-)
PS. This tends to be an excellent and helpful newsgroup, thanks.
Regards,
Svein B.
"John Hynes" <jo...@hynes.plus.com> wrote in message
news:ekFJ9.379$h43.60322@stones...
RowHeadersVisible can be false.
It is the MappingName's that are important, these must match the Table/Row
names in the dataset.
The automatically generated code doesn't do this (Bug?)
John
"Svein B." <sb-...@amc-technology.com> wrote in message
news:3df75a6b$1...@news.broadpark.no...