就是在 dataGridView1的单元格的单击事件中添加如下代码
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string t1 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船号"].Value.tostring();
string t2 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船名"].Value.tostring();
string t3 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船只类型"].Value.tostring();
string t4 = Convert.ToDateTime(dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["注册时间"].Value).ToShortDateString();
textBox1.Text = t1;
textBox2.Text = t2;
textBox3.Text = t3;
textBox4.Text = t4;
}
即可实现DGV的行数据的提取,也可以根据提取的一个单元格的数据进行数据库的查找,然后数据再绑定到控件上。
textbox.databindings.add("text",dataset,"login.id");//这个可以把数据绑定到控件上面了,后面那个是login表的id字段
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string t1 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船号"].Value.tostring();
string t2 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船名"].Value.tostring();
string t3 = dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["船只类型"].Value.tostring();
string t4 = Convert.ToDateTime(dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["注册时间"].Value).ToShortDateString();
textBox1.Text = t1;
textBox2.Text = t2;
textBox3.Text = t3;
textBox4.Text = t4;
}
即可实现DGV的行数据的提取,也可以根据提取的一个单元格的数据进行数据库的查找,然后数据再绑定到控件上。
textbox.databindings.add("text",dataset,"login.id");//这个可以把数据绑定到控件上面了,后面那个是login表的id字段