Add Header on Datagrid

albertkhor

Well-known member
Joined
Jan 12, 2006
Messages
150
Programming Experience
Beginner
Header on Datagrid

my excel hv data n without header, so when i bind with datagrid my first row data with before header in datagrid! i want to avoid this, can someone teach me? What i want is like below:

Column1 Column2 <------- i want system auto display the column number
Sample1 0132736475
Sample2 0172837465


the result i get now in datagrid, u can notice that the first row data in excel will auto become header:
 

Attachments

  • datagrid.bmp
    61.9 KB · Views: 80
Last edited:
So what do you ant to be the headers? Name, Phone and Email or Column1, Column2 and Column3? If you want the column headers to be different to the column names you need to use DataGridColumnStyles, but you can't have the column names actually in the grid itself unless they are part of the data contained in the table.
 
jmcilhinney said:
So what do you ant to be the headers? Name, Phone and Email or Column1, Column2 and Column3? If you want the column headers to be different to the column names you need to use DataGridColumnStyles, but you can't have the column names actually in the grid itself unless they are part of the data contained in the table.

Hi jmcilhinney,
thx for reply me! what i want is Column1, Column2, and Column3. The column number will base on how many column in the data (excel).
 
Then, as I said, you'll need to use column styles to set the headers. Follow the Windows Forms FAQ link in my signature. It has a wealth of information about using the DataGrid and I'm sure it will include what you want.
 
jmcilhinney said:
Then, as I said, you'll need to use column styles to set the headers. Follow the Windows Forms FAQ link in my signature. It has a wealth of information about using the DataGrid and I'm sure it will include what you want.

hi jmcilhinney,
i cannot find the topic i want!
 
I suggest that you do some reading on the DataGridColumnStyle class. It has a HeaderText property, so once you learn how to apply them to a DataGrid you are set. I'm sure that WinForms FAQ would have example code for adding column styles, or you can read the class overview in the help/MSDN library
 
Back
Top