實際上就是把gridview的數據源轉成數組嘛

解决方案 »

  1.   

    GridView数据源一般都是DataTable,循环读取DataTable把数据放到数组里
      

  2.   

    using System;
    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
            }
        }
    }
      

  3.   

    你的Gridview里不可能都是数字吧,如果有文字就不能用int数组了using System;
    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;
        }
    }
      

  4.   

    参考:
    http://blog.csdn.net/flygoldfish/archive/2006/05/16/741351.aspx
      

  5.   

    遍历数据源,加入动态数组ArrayList