日期:2014-05-20 浏览次数:20823 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace dataGridDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.DataSource = getTable();
}
private void button1_Click(object sender, EventArgs e)
{
string product = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString();
string version = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
Form2 frm = new Form2();
((TextBox)frm.Controls["textBox1"]).Text = product;
((TextBox)frm.Controls["textBox2"]).Text = version;
frm.Show();
}
public DataTable getTable()
{
DataTable tblDatas = new DataTable("Datas");
DataColumn dc = null;
//赋值给dc,是便于对每一个datacolumn的操作
dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//自动增加
dc.AutoIncrementSeed = 1;//起始为1
dc.AutoIncrementStep = 1;//步长为1
dc.AllowDBNull = false;//
dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));