Hello everyone,

First of all sorry for my English.

How can I rename headers in dataGridView? When I press on Find button all works just fine. I get the information wich I want.
But headers of columns in dataGridView have names just like in database (PersonID, Name_Person,... ).

I would like to have text of headers with other names --> ID, Name, ..etc. How can I solve this problem?

Example of my code (button Find):

private void btnFind_Click(object sender, EventArgs e)
                dataGridView1.DataSource = null;

                string povezava = @"Provider=Microsoft.Jet.OLEDB.4.0;"
                + @"Data Source=D:\\kadri_v2.mdb";

                string poizvedba = "SELECT .... FRMOM .... WHERE ";

                DataTable Tabela = new DataTable();
                OleDbDataAdapter Adapter = new OleDbDataAdapter(poizvedba, povezava);
                OleDbCommandBuilder cb = new OleDbCommandBuilder(Adapter);

                BindingSource bs = new BindingSource();
                bs.DataSource = Tabela;

                DataGridView dgView = new DataGridView();
                dgView.DataSource = bs;
                dataGridView1.DataSource = Tabela;
            catch (Exception ex)
                MessageBox.Show("Error: " + ex);


Recommended Answers

All 3 Replies

If you didn't change it before in the designer,you can simply do this.

dataGridView1.Columns[ 0 ].HeaderText = "Foobar";

PierlucSS thanks for your help. It works perfectly.

If your satisfied with the answer, please mark this thread as solved :)

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.