请教,dataGridView1取值问题
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;
//获得当前行的第一列的值
string value1 = dataGridView1.Rows[rowindex].Cells["qq_id"].Value.ToString();
textBox1.Text = value1;
}
private void button1_Click(object sender, EventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;
//获得当前行的第一列的值
string value1 = dataGridView1.Rows[rowindex].Cells["qq_id"].Value.ToString();
textBox1.Text = value1;
}
请教下,为什么点击button1按钮 text可以显示,点击dataGridView1不能显示值
------解决方案-------------------- C# code
string value1 = dataGridView1.Rows[e.Rowindex].Cells[e.ColunmIndex].Value.ToString();
textBox1.Text = value1;
------解决方案--------------------
if (!DBNull.Value.Equals(DataGridView1.CurrentCell.Value))
{
string str = DataGridView1.CurrentCell.Value.ToString();
textBox1.Text =str;
}
最好是用CurrentCellChanged事件处理