vs2005里做一个记录浏览列表,用datagridview,鼠标点击不同的记录行,下面对应的textbox值能相应改变
我用的datagridview的dataGridView1_CellContentClick和dataGridView1_CurrentCellChanged方法,都只有鼠标准确点击在cell里的值上面,才会触发事件,点在cell的空白处,或行头则没反应
想要使鼠标点击在这行的任意地方都能触发事件怎么做
我用的datagridview的dataGridView1_CellContentClick和dataGridView1_CurrentCellChanged方法,都只有鼠标准确点击在cell里的值上面,才会触发事件,点在cell的空白处,或行头则没反应
想要使鼠标点击在这行的任意地方都能触发事件怎么做
{ }
用这个事件应该可以。
private void dataGridView_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
string str = dataGridView.SelectedRows[0].Cells[0].Value.ToString();//这里获取单元格里面的值,你可以改一下
textBox1.Text=str; }
}
Eg;
private void dgvUserInfo_CellClick(object sender, DataGridViewCellEventArgs e)
{
txtName.Text = Convert.ToString(dgvAreaInfo[0, dgvAreaInfo.CurrentCell.RowIndex].Value).Trim();
txtAddress.Text = Convert.ToString(dgvAreaInfo[1, dgvAreaInfo.CurrentCell.RowIndex].Value).Trim();
}