1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Headers dataGridView C#

Discussion in 'C#' started by MatejM, Aug 28, 2010.

  1. MatejM

    MatejM New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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)
    {
    try
    {
    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);
    Adapter.Fill(Tabela);

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

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

Share This Page