设置DataGridView的数据源 [英] setting Data source of a DataGridView
本文介绍了设置DataGridView的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据持有者名单
I have a List of data holder
IList<dataholder> dataList = new List<dataholder>();
dataList = GetDataList();
datagridview1.dataSource = datalist;
</dataholder></dataholder>
从上面的代码中,我可以将数据持有人的类属性设置为列标题的数据源
我有一个带有自定义列标题文本的字符串数组.
即使将数据源设置为
from the above code i am able to set my datasource with the dataholder class properties as the column header
I have an array of string with custom column headers text..
How can i keep this array values as my DataGridview column header text even after setting the data source
推荐答案
,也许将DataGridView.AutoGenerateColumns设置为false后,如何仍可以将该数组值保留为DataGridview列标题文本.
Perhaps set DataGridView.AutoGenerateColumns to false.
我找到了解决方法
可以通过在设置数据源后添加列标题文本来实现
就像下面的
i got the solution
it can be achieved by adding the column headertext after setting datasource
like below
dataPreviewDataGridView.Columns[colNo].HeaderText = columnName;
这篇关于设置DataGridView的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文