添加一个datagridview
添加两个textbox
添加事件dataGridView1_CellClick
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("value");
Random rd=new Random();
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["id"] = i;
dr["value"] = rd.Next();
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;
dataGridView1.CellClick+=dataGridView1_CellClick;
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex > -1 && e.RowIndex > -1)
{
//显示一个单元格。
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
//显示一行
DataGridViewRow dr = dataGridView1.Rows[e.RowIndex];
textBox2.Text = string.Empty;//清空原有值
foreach (DataGridViewCell item in dr.Cells)
{
textBox2.Text += item.Value.ToString() + " ";
}
}
}
string 字符 = dataGridView.Rows[dataGridView.CurrentCellAddress.Y].Cells[1].Value.ToString();
http://blog.csdn.net/xianfajushi/article/details/8141972
你是要读取选中的还是读取第一行?