C#用datagridview 无法使选中行的内容显示在下面的textbox里是怎么回事
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 医院业务系统
{
public partial class 医生信息管理 : Form
{
public 医生信息管理()
{
InitializeComponent();
}
private void 医生信息管理_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string con, sql;
con = "Server=.;Database=yy;Trusted_Connection=SSPI";
sql = "select * from 医生信息";
SqlConnection mycon = new SqlConnection(con);
mycon.Open();
MessageBox.Show("连接成功!"); //弹出窗口,用于测试数据库连接是否成功。
SqlDataAdapter myda = new SqlDataAdapter(sql, con);
DataSet myds = new DataSet();
myda.Fill(myds, "医生信息");
dataGridView1.DataSource = myds.Tables["医生信息"];
mycon.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBoxGongHao.ReadOnly = true;
textBoxGongHao.Text = dataGridView1.Rows[e.RowIndex].Cells["工号"].Value.ToString();
textBoxXingMing.Text = this.dataGridView1.CurrentRow.Cells["姓名"].Value.ToString();
textBoxXinBie.Text = this.dataGridView1.CurrentRow.Cells["性别"].Value.ToString();
textBoxBuMenHao.Text = this.dataGridView1.CurrentRow.Cells["部门号"].Value.ToString();
textBoxZhiCheng.Text = this.dataGridView1.CurrentRow.Cells["职称"].Value.ToString();
textBoxYiShengJianJie.Text = this.dataGridView1.CurrentRow.Cells["医生简介"].Value.ToString();
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 医院业务系统
{
public partial class 医生信息管理 : Form
{
public 医生信息管理()
{
InitializeComponent();
}
private void 医生信息管理_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string con, sql;
con = "Server=.;Database=yy;Trusted_Connection=SSPI";
sql = "select * from 医生信息";
SqlConnection mycon = new SqlConnection(con);
mycon.Open();
MessageBox.Show("连接成功!"); //弹出窗口,用于测试数据库连接是否成功。
SqlDataAdapter myda = new SqlDataAdapter(sql, con);
DataSet myds = new DataSet();
myda.Fill(myds, "医生信息");
dataGridView1.DataSource = myds.Tables["医生信息"];
mycon.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBoxGongHao.ReadOnly = true;
textBoxGongHao.Text = dataGridView1.Rows[e.RowIndex].Cells["工号"].Value.ToString();
textBoxXingMing.Text = this.dataGridView1.CurrentRow.Cells["姓名"].Value.ToString();
textBoxXinBie.Text = this.dataGridView1.CurrentRow.Cells["性别"].Value.ToString();
textBoxBuMenHao.Text = this.dataGridView1.CurrentRow.Cells["部门号"].Value.ToString();
textBoxZhiCheng.Text = this.dataGridView1.CurrentRow.Cells["职称"].Value.ToString();
textBoxYiShengJianJie.Text = this.dataGridView1.CurrentRow.Cells["医生简介"].Value.ToString();
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询