實際上就是把gridview的數據源轉成數組嘛
解决方案 »
- c#面试题大家猜结果是多少不许运行先
- 如何用代码访问域上的磁盘,然后设为本地的磁盘映射
- 100分跪求c#二次开发操作捕获
- 到底哪错了
- 如何判断treeview对象没有现在任何节点(急)?
- ???菜鸟想学udp,想做个程序,监听8888端口,收到字符串后,用messagebox.show()函数弹出来??怎么做呢??
- Remoting的问题,不知道大家有没有遇到过,帮忙看下。
- 各位大虾!我用Iframe嵌了一个数据提交的页面,但老是出错,请大虾帮忙
- help:我用streamwrite写入一个ini文件,但再取出来中文为何是乱码?
- 静态成员是不是只能通过CLASS来访问??
- 几个期末考试题目,大家一起看看
- 求助 C# 写的 学生学籍管理系统 的论文!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication44
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); DataTable DT = new DataTable();
DT.Columns.Add("c1", typeof(int));
DT.Columns.Add("c2", typeof(int));
DT.Columns.Add("c3", typeof(int));
DT.Rows.Add(new Object[] { 1, 2, 3 });
DT.Rows.Add(new Object[] { 11, 22, 33 });
DT.Rows.Add(new Object[] { 111, 222, 333 }); DataGridView DGV = new DataGridView();
DGV.Parent = this;
DataGridViewTextBoxColumn Column = new DataGridViewTextBoxColumn();
Column.DataPropertyName = "c1";
DGV.Columns.Add(Column);
Column = new DataGridViewTextBoxColumn();
Column.DataPropertyName = "c2";
DGV.Columns.Add(Column);
Column = new DataGridViewTextBoxColumn();
Column.DataPropertyName = "c3";
DGV.Columns.Add(Column);
DGV.DataSource = DT; int[][] A = new int[DT.Rows.Count][]; for (int i = 0; i < DT.Rows.Count; i++)
DT.Rows[i].ItemArray.CopyTo(A[i] = new int[DT.Columns.Count], 0); String S = String.Empty;
for (int i = 0; i < A.Length; i++)
for (int j = 0; j < A[i].Length; j++)
S += A[i][j].ToString() + " "; MessageBox.Show(S); // 1 2 3 11 22 33 111 222 333
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary;
using System.Data;namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
DataTable table = new DataTable();//创建Gridview数据源
table.Columns.Add(new DataColumn("ID",typeof(Int32)));
table.Columns.Add(new DataColumn("Name", typeof(String)));
table.Rows.Add(1,"aaa");
table.Rows.Add(2, "bbb");
table.Rows.Add(3, "ccc"); StInfo[] arr = new StInfo[3];//用结构体存放Gridview行数据
StInfo yang;
int i = 0;
foreach (DataRow row in table.Rows)
{
yang = new StInfo();
yang.id = int.Parse(row[0].ToString());
yang.name = row[1].ToString();
arr[i] = yang;
i++;
} for (i = 0; i < arr.Length; i++)
{
Console.WriteLine("Id:{0},Name:{1}", arr[i].id.ToString(), arr[i].name);
} Console.ReadKey();
}
} struct StInfo
{
public int id;
public string name;
}
}
http://blog.csdn.net/flygoldfish/archive/2006/05/16/741351.aspx