C#这样一个问题,点击datagridview,将点击的这一行的信息显示在窗体控件上。
textbox,comobox,已经解决,求picturebox的解决方案。我的代码是这样写的:privatevoiddataGridView1_CellMouseCli...
textbox,comobox,已经解决,求picturebox的解决方案。我的代码是这样写的:
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rownuber = dataGridView1.CurrentCell.RowIndex;
textBox2.Text = dataGridView1.Rows[rownuber].Cells[0].Value.ToString();
textBox3.Text = dataGridView1.Rows[rownuber].Cells[1].Value.ToString();
comboBox1.Text = dataGridView1.Rows[rownuber].Cells[2].Value.ToString();
}
public static Image ReturnPhoto(byte[] streamByte) //声明了一个方法
{
MemoryStream ms = new MemoryStream(streamByte);
Image img = Image.FromStream(ms);
return img;
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)//连接数据库,调用方法
{
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter adp = new SqlDataAdapter("select uimage from users where uid='"+textBox2.Text +"' ", conn);
DataSet ds = new DataSet();
adp.Fill(ds);
this.pictureBox1.Image = ReturnPhoto((byte[])ds.Tables[0].Rows[0][0]);
} 展开
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rownuber = dataGridView1.CurrentCell.RowIndex;
textBox2.Text = dataGridView1.Rows[rownuber].Cells[0].Value.ToString();
textBox3.Text = dataGridView1.Rows[rownuber].Cells[1].Value.ToString();
comboBox1.Text = dataGridView1.Rows[rownuber].Cells[2].Value.ToString();
}
public static Image ReturnPhoto(byte[] streamByte) //声明了一个方法
{
MemoryStream ms = new MemoryStream(streamByte);
Image img = Image.FromStream(ms);
return img;
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)//连接数据库,调用方法
{
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter adp = new SqlDataAdapter("select uimage from users where uid='"+textBox2.Text +"' ", conn);
DataSet ds = new DataSet();
adp.Fill(ds);
this.pictureBox1.Image = ReturnPhoto((byte[])ds.Tables[0].Rows[0][0]);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询