在DATAGRIDVIEW中点击任一行,该行中的数据对应显示在窗体的 一系列TEXTBOX控件中,怎样操作?

解决方案 »

  1.   

    用绑定来实现,例如:
    DataView dv = yourDataTable.DefaultView;
    yourDataGridView.DataSource = dv;
    yourTextBox.DataBindings.Add("Text", dv, yourFieldName );
      

  2.   

    private void dgIrrigateCustomer_Click(object sender, EventArgs e)
            {
                if (dgIrrigateCustomer.CurrentRow != null)
                {
                    foreach (Control ctrl in this.Controls)
                    {
                        string ctrlName = ctrl.Name.Trim();
                        if (ctrlName.StartsWith("txt"))
                        {
                            ctrl.Enabled = false;
                        }
                    }
           
                    txtSid.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[1].Value.ToString();
                    txtName.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[2].Value.ToString();
                }
            }
    dgIrrigateCustomer是datagridview的名称。
      

  3.   

    綁定:
    SqlDataAdatper.fill(dt);
    this.datagrid1.datasource=dt;
    private void SetGrid()
    {
        txtId.databindings.add("TEXT",dt,"id");
    .........
    .........
    }