如何在c#中的datagridview中将列表项作为标题 [英] how to make a list item as header in datagridview in c#

查看:341
本文介绍了如何在c#中的datagridview中将列表项作为标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,其中包含值列表[0] =名称,列表[1] = id,列表[2] = gcghchg,列表[3] = 2012



i需要将列表绑定到datagridview,但是list [0],list [1]应该是datagridview的头

解决方案

循环遍历列表中的项集合和将DataGridViewColumn添加到DataGredViewColumnCollection [ ^ ]。这就是全部!



另一种方法是使用 AddRange方法 [ ^ ]:

 < span class =code-keyword> this  .dataGridView1.Columns.AddRange( new  System.Windows.Forms.DataGridViewColumn [] {stringList.ToArray( )}); 


i have a list containing values list[0]=name, list[1]=id, list[2]=gcghchg ,list[3]=2012

i need to bind the list to datagridview, but list[0], list[1] should be header for datagridview

解决方案

Loop through the collection of items in list and add DataGridViewColumn to the DataGredViewColumnCollection[^]. That's all!

Another way is to use AddRange method[^]:

this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {stringList.ToArray()});


这篇关于如何在c#中的datagridview中将列表项作为标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆