Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i am trying to rename the column header of a datagrid that is being pupulated from a dataset that i got from my Database.
The problem is that i need to create a mapping to map new names to the columns headers different from the ones extracted from the database.

The following is my code and its not working ... error:TableStyles cannot be resolved.

 DataGridTableStyle myGridStyle =
                    new DataGridTableStyle ();
                    myGridStyle.MappingName = "Users";

DataGridColumnStyle colStyle1 =
                    new DataGridBoolColumn ();
                    colStyle2.MappingName = "Salary";
                    DataGridColumnStyle colStyle2 =
                    new DataGridBoolColumn ();
                    colStyle2.MappingName = "Position";

                    // Add column styles to table style.
                    myGridStyle.GridColumnStyles.Add (colStyle1);
                    myGridStyle.GridColumnStyles.Add (colStyle2);

dgvResults.TableStyles.Add (myGridStyle);
Posted
Updated 13-Jul-10 21:18pm
v2

Try following

Just assign your DataTable to datagridview, and change the name of the column header.

C#
dataGridView1.DataSource=dataSet1.Tables[0];
dataGridView1.Columns[0].HeaderText="My Custom Header";



HTH
 
Share this answer
 
Jinal's answer is correct. But an easier way is to rename the columns in Visual Studio.

Steps:
1. Select the Datagriview you want to modify.
2. Click the DataGridView tasks small button, and click the Edit Columns link
3. On the Edit Columns dialog, select the column you wish to rename, and change the HeaderText to your desired name.
4. Click OK and you're done!
 
Share this answer
 
in free pascal

CSS
DBGrid1.Columns[0].Title.Caption   :='الاسم التجارى';
   DBGrid1.Columns[1].Title.Caption   :='الاسم العلمى';
    DBGrid1.Columns[2].Title.Caption   :='السعر';
     DBGrid1.Columns[3].Title.Caption   :='ملاحظات';
 
Share this answer
 
Comments
CHill60 7-Oct-14 2:29am    
Off-topic. This 4 year post is tagged C#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900