C# DataGridView显示数组
来源:互联网 发布:zhao家人是什么 知乎 编辑:程序博客网 时间:2024/05/01 09:59
private void Form1_Load(object sender, EventArgs e)
//dataGridView1.DataSource = intarray;//使用字符串数组,结果显示字符串的第一个公共属性Length
//第二种做法
Item[] items = new Item[]
{
new Item("one"),
new Item("two"),
new Item("three")
}
class Item
{
{
get { return txt; }
}
public Item(string text)
{
this.txt = text;
}
}
//另附以下程序
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0) //当表头选中时
{
return;
}
if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == "two") //当选中“two”时,checkBox1被选中
{
checkBox1.Checked = true;
}
else
{
checkBox1.Checked = false;
{
//第一种做法(不如人意,没有达到要求,只显示字符串的长度)
//string[] intarray =new string[] {"one","two","three"};//dataGridView1.DataSource = intarray;//使用字符串数组,结果显示字符串的第一个公共属性Length
//第二种做法
Item[] items = new Item[]
{
new Item("one"),
new Item("two"),
new Item("three")
};
this.dataGridView1.DataSource = items;}
class Item
{
private string txt;
public string Text{
get { return txt; }
}
public Item(string text)
{
this.txt = text;
}
}
//另附以下程序
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0) //当表头选中时
{
return;
}
if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == "two") //当选中“two”时,checkBox1被选中
{
checkBox1.Checked = true;
}
else
{
checkBox1.Checked = false;
}
}
//第一种做法运行结果如下:
//第二种做法行结果如下:
//当选中“two”时,checkBox1被选中
DataGridView 控件使用方法可参考:
http://blog.csdn.net/weishuchan/article/details/7981726
http://blog.sina.com.cn/s/blog_4935bf700100mtv7.html
- C# DataGridView显示数组
- C#中使用DataGridView控件显示数组中的内容
- C#中使用DataGridView显示二维数组中的内容
- C#中使用DataGridView显示二维数组中的内容
- C# datagridview显示行号
- access显示到dataGridView C#
- C#中DataGridView显示行号
- C# dataGridView隔行显示不同颜色
- C#中的datagridview显示行号
- C# DataGridView显示行号方法。
- C# DataGridView隔行显示不同的颜色
- C# DataGridView隔行显示不同的颜色
- C# DataGridView隔行显示不同的颜色
- C# 面试 (datagrid || datagridView显示数据)
- C# DataGridView隔行显示不同的颜色
- C# DataGridView隔行显示不同的颜色
- c# bindingSource联合dataGridView显示数据
- C# winfrom中 DataGridView中显示行号
- NullPointerException异常
- 嵌入式学习笔记(8)——51单片机之矩阵键盘
- openstack 镜像制作
- 一个动物类的小游戏【类和对象】
- Android 调用Gmail发送邮件
- C# DataGridView显示数组
- 大数相加 + 方法2
- 大数相加 + 方法1
- OpenStack Nova Internals – pt1 – Overview
- 大数问题,两大数相乘 +方法1
- 大数问题+n!
- java.lang.ClassCastException异常
- 输入一颗二元树,从上往下按层打印树的每个结点,同一层中按照从左往右的顺序打印(16)
- 三元组--数据结构