Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I managed to bind the data grid view to it's own item source and also able to bind to respective column data member.

I have problem binding with the header of each data column because the data context seems to be bound to a given item source.

My question is, how do I bind to each column header? Or, is there a way to bind outside of the item source?

I need help urgently. Thanks!
Posted

You can use below code :


C#
string myConnection = conn.ConnectionString.ToString();//"Data Source=MDT765;Initial Catalog=TST;User Id=user;Password=user@123;";
    SqlDataAdapter sqlcom0 = new SqlDataAdapter("SELECT Id,Name,Pos,Loc FROM Employee", myConnection);
    DataSet ds0 = new DataSet();
    sqlcom0.Fill(ds0);
    dataGridView1.DataSource = ds0.Tables[0].DefaultView;
    dataGridView1.Columns[0].HeaderText = "A";
    dataGridView1.Columns[1].HeaderText = "A1";
    dataGridView1.Columns[2].HeaderText = "A2";
    dataGridView1.Columns[3].HeaderText = "A3";

    dataGridView1.Refresh();


Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.
 
Share this answer
 
Google will give you lots of articles. Perhaps you should search it before asking quesion. Anyways here is what found for you.Using The Silverlight DataGrid[^]
 
Share this answer
 

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