110,533
社区成员
发帖
与我相关
我的任务
分享
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获得当前选中的行
int rowindex = e.RowIndex;
try
{
textBox1.Text = dataGridView1.Rows[rowindex].Cells[0].Value.ToString(); //获得当前行的第0列的值
comboBox1.Text = dataGridView1.Rows[rowindex].Cells[1].Value.ToString(); //获得当前行的第一列的值
}
catch (Exception exc) { }
}
DataTable dt;
private string text;
private string combox;
/// <summary>
/// 获取双击GridView中的数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
//双击行时能得到rowIndex
int index = e.RowIndex;
//从全局变量dt中取出弹出界面需要的值
string text = dt.Rows[index]["需要的值textbox"].ToString();
string combox = dt.Rows[index]["需要的值combobox"].ToString();
//利用构造函数传值到弹出页面,并在构造函数中做赋值操作
Form1 frm = new Form1(text, combox);
frm.ShowDialog();
}
private void BindData()
{
//绑定数据的时候把DataTable保存为全局变量dt
dt = new DataTable();
this.dataGridView1.DataSource = dt;
}
/// <summary>
/// 弹出界面的构造函数
/// </summary>
/// <param name="text"></param>
/// <param name="combox"></param>
public Form1(string text, string combox)
{
// TODO: Complete member initialization
this.textBox.Text = text;
this.combox.selectItem = combox;
}