下面的代码怎么实现不了我想要的那个点击datagridview中任意一行,把该行的值对应用textBox显示呢?
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int indextemp = dataGridView1.CurrentCell.RowIndex;//当前行号
if (indexdelete != 1)
{
DataGridViewCheckBoxCell checkboxtemp = (DataGridViewCheckBoxCell)dataGridView1.Rows[indextemp].Cells[0];
checkboxtemp.Value = 1;//设置当前行的checkbox为选中状态
DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dataGridView1.Rows[index].Cells[0];
checkbox.Value = 0;//设置上次点击的行的checkbox为非选中状态
index = indextemp;//暂存本次的点击的行号,作为下一次的“上次点击的行”
}
else
{
DataGridViewCheckBoxCell checkboxtemp = (DataGridViewCheckBoxCell)dataGridView1.Rows[indextemp].Cells[0];
checkboxtemp.Value = 1;//设置当前行的checkbox为选中状态
index = indextemp;//暂存本次的点击的行号,作为下一次的“上次点击的行”
indexdelete = 0;
}
textBox1.Text = dataGridView1.Rows[indextemp].Cells[1].Value.ToString();
textBox2.Text = dataGridView1.Rows[indextemp].Cells[3].Value.ToString();
textBox3.Text = dataGridView1.Rows[indextemp].Cells[4].Value.ToString();
textBox4.Text = dataGridView1.Rows[indextemp].Cells[5].Value.ToString();
textBox5.Text = dataGridView1.Rows[indextemp].Cells[6].Value.ToString();
textBox6.Text = dataGridView1.Rows[indextemp].Cells[7].Value.ToString();
textBox7.Text = dataGridView1.Rows[indextemp].Cells[8].Value.ToString();
textBox8.Text = dataGridView1.Rows[indextemp].Cells[9].Value.ToString();
textBox9.Text = dataGridView1.Rows[indextemp].Cells[10].Value.ToString();
textBox10.Text = dataGridView1.Rows[indextemp].Cells[11].Value.ToString();
textBox11.Text = dataGridView1.Rows[indextemp].Cells[12].Value.ToString();
textBox12.Text = dataGridView1.Rows[indextemp].Cells[13].Value.ToString();
textBox13.Text = dataGridView1.Rows[indextemp].Cells[14].Value.ToString();
textBox14.Text = dataGridView1.Rows[indextemp].Cells[15].Value.ToString();
textBox15.Text = dataGridView1.Rows[indextemp].Cells[16].Value.ToString();
textBox16.Text = dataGridView1.Rows[indextemp].Cells[17].Value.ToString();
//try
//{
// int n = dataGridView1.CurrentCell.RowIndex;
// if (n>0 && n < dataGridView1.RowCount - 1)
// {
// textBox1.Text = dataGridView1[0, n].Value.ToString().Trim();
// textBox2.Text = dataGridView1[1, n].Value.ToString().Trim();
// textBox3.Text = dataGridView1[2, n].Value.ToString().Trim();
// textBox4.Text = dataGridView1[3, n].Value.ToString().Trim();
// textBox5.Text = dataGridView1[4, n].Value.ToString().Trim();
// textBox6.Text = dataGridView1[5, n].Value.ToString().Trim();
// textBox7.Text = dataGridView1[6, n].Value.ToString().Trim();
// textBox8.Text = dataGridView1[7, n].Value.ToString().Trim();
// textBox9.Text = dataGridView1[8, n].Value.ToString().Trim();
// textBox10.Text = dataGridView1[9, n].Value.ToString().Trim();
//