日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#.winform,datagridview,数组,绑定,字符串,字符串数组绑定datagridview显示,长度,显示数组内容...

發布時間:2023/11/30 C# 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#.winform,datagridview,数组,绑定,字符串,字符串数组绑定datagridview显示,长度,显示数组内容... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用字符串數組綁定datagridveiw控件的時候,默認顯示的是字符串的長度,是因為網格查找數組對象的第一個屬性,并且顯示這個屬性,長度就是第一個屬性,可是我們要顯示的是字符串的內容。
下面首先是默認顯示圖片和代碼

using?System;
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;
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显示,长度,显示数组内容...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。