c#.winform,datagridview,数组,绑定,字符串,字符串数组绑定datagridview显示,长度,显示数组内容...
生活随笔
收集整理的這篇文章主要介紹了
c#.winform,datagridview,数组,绑定,字符串,字符串数组绑定datagridview显示,长度,显示数组内容...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用字符串數組綁定datagridveiw控件的時候,默認顯示的是字符串的長度,是因為網格查找數組對象的第一個屬性,并且顯示這個屬性,長度就是第一個屬性,可是我們要顯示的是字符串的內容。
下面首先是默認顯示圖片和代碼
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
namespace?WindowsApplication1
{
????public?partial?class?Form10?:?Form
????{
????????public?Form10()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender,?EventArgs?e)
????????{
????????????string[]?str?=?new?string[]?{?"one",?"two",?"three"?};
????????????this.dataGridView1.DataSource?=?str;
???????????????????}
????}
????}
我們需要包裝一下數組,方法如下:
圖片預覽
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
namespace?WindowsApplication1
{
????public?partial?class?Form10?:?Form
????{
????????public?Form10()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender,?EventArgs?e)
????????{
??????????
????????????Item[]?items?=?new?Item[]?{?new?Item("one"),?new?Item("two"),?new?Item("three")?};
????????????this.dataGridView1.DataSource?=?items;
????????}
????}
????class?Item
????{
????????private?string?_text;
????????public?string?Text
????????{
????????????get?{?return?_text;?}
????????}
????????public?Item(string?text)
????????{
????????????this._text?=?text;
????????}
????}
}
?
以上內容來自:http://www.cnblogs.com/virusswb/archive/2008/05/25/1206934.html
?
轉載于:https://www.cnblogs.com/jRoger/articles/1862908.html
總結
以上是生活随笔為你收集整理的c#.winform,datagridview,数组,绑定,字符串,字符串数组绑定datagridview显示,长度,显示数组内容...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vss和vs2008组合搭建源代码管理器
- 下一篇: ActionScript 3.0 学习笔