.NET dataGridView选中行显示到TEXTBOX中
if(dataGridView1.SelectedRows.Count==1){tbId.Text=dataGridView1.CurrentRow.Cells[0].V...
if (dataGridView1.SelectedRows.Count==1)
{
tbId.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
tbName.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
tbAge.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
tbZhuanye.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
tbBeizhu.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
if (dataGridView1.CurrentRow.Cells[3].Value.ToString().Equals("男"))
{
rbMan.Checked = true;
}
else
{
rbWoman.Checked = true;
}
}
else
{
MessageBox.Show("未选中整条记录或选中多行记录");
}
选中一行TEXTBOX中没显示啊??? 展开
{
tbId.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
tbName.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
tbAge.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
tbZhuanye.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
tbBeizhu.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
if (dataGridView1.CurrentRow.Cells[3].Value.ToString().Equals("男"))
{
rbMan.Checked = true;
}
else
{
rbWoman.Checked = true;
}
}
else
{
MessageBox.Show("未选中整条记录或选中多行记录");
}
选中一行TEXTBOX中没显示啊??? 展开
展开全部
在dataGridView的
CellContentClick事件中写代码
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 6 && e.RowIndex != -1 && !dataGridView.Rows[e.RowIndex].IsNewRow)//e.ColumnIndex是指你在某一列触发了这个事件,比如在第六列是一个BUTTON,e.ColumnIndex就为6
{
textbox.Text = dataGridView.Rows[e.RowIndex].Cells["dataGridViewTextBoxColumn1"].Value.ToString();//选中行的名称为dataGridViewTextBoxColumn1的值。
//若想得到选中行的index,则:
textbox.Text=e.RowIndex.ToString();
}
}
CellContentClick事件中写代码
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 6 && e.RowIndex != -1 && !dataGridView.Rows[e.RowIndex].IsNewRow)//e.ColumnIndex是指你在某一列触发了这个事件,比如在第六列是一个BUTTON,e.ColumnIndex就为6
{
textbox.Text = dataGridView.Rows[e.RowIndex].Cells["dataGridViewTextBoxColumn1"].Value.ToString();//选中行的名称为dataGridViewTextBoxColumn1的值。
//若想得到选中行的index,则:
textbox.Text=e.RowIndex.ToString();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
方法一: //DataGridView的click事件
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
private void dataGridView1_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count > 0)
{
this.txtId.Text = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
}
}
方法二:Cellclick 事件
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
this.textBox1.Text = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
catch
{
}
}
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
private void dataGridView1_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count > 0)
{
this.txtId.Text = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
}
}
方法二:Cellclick 事件
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
this.textBox1.Text = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
catch
{
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询