如何绑定到数据网格视图的标题? [英] How to bind to a header of data grid view?
本文介绍了如何绑定到数据网格视图的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法将数据网格视图绑定到它自己的项目源,并且还能够绑定到相应的列数据成员.
我在与每个数据列的标题绑定时遇到问题,因为数据上下文似乎已绑定到给定的项目源.
我的问题是,如何绑定到每个列标题?或者,是否有一种方法可以在商品来源之外进行绑定?
我迫切需要帮助.谢谢!
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!
推荐答案
您可以使用以下代码:
You can use below code :
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();
希望这会有所帮助,如果是,则接受并投票回答,否则返回您的查询
--Rahul D.
Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.
Google将为您提供许多文章.也许您应该在提出疑问之前先进行搜索.无论如何,这里都是为您找到的东西.使用Silverlight DataGrid [ ^ ]
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[^]
这篇关于如何绑定到数据网格视图的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文