Click here to Skip to main content
15,885,978 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
In my form I have taken one combobox where I use to display the Plantname
and on click event of button control Im retrieving the related information from the database . I have used datagridview for data display . I also want to display the plant images in a datagridview . Its is possible in web application but how to do it in a window application.


I'm able to display values in the datagridview and when i click on the particular cell that value of the text get copied to textbox1.text ..


Now i want the image of that same name which got displayed at textbox1..I have used one picture box where on clicking the datagridview cell or textbox the images get displayed one after one im using the code below

private void Disease_Load(object sender, EventArgs e)
{

String constring = "Data Source=|DataDirectory|abc.mdb;Jet OLEDB:Database Password=abc#;Provider=Microsoft.jet.oledb.4.0";
OleDbConnection conn = new OleDbConnection(constring);
OleDbDataAdapter da1 = new OleDbDataAdapter("Select Distinct DCured from Diseases", conn);
DataSet dset1 = new DataSet();
da1.Fill(dset1, "Diseases");

if (dset1.Tables["Diseases"].Rows.Count > 0)
{

comboBox1.DataSource = dset1.Tables["Diseases"];
comboBox1.DisplayMember = "DCur";
comboBox1.ValueMember = "DCur";
comboBox1.SelectedIndex = 0;
//IHBT(CSIR)
}
conn.Close();
}

private void button2_Click(object sender, EventArgs e)
{
try
{
String Constring = "Data Source=|DataDirectory|abc.mdb; Jet OLEDB:Database Password= abc#; Provider=Microsoft.jet.oledb.4.0";
OleDbDataAdapter da3 = new OleDbDataAdapter("SELECT Photograph.Photographs,Diseases.SName AS SName FROM (Systematics INNER JOIN Photograph ON Systematics.[ID] = Photograph.[ID]) INNER JOIN Diseases ON Systematics.[SName] = Diseases.[SName] Where DCured='" + comboBox1.Text + "'", Constring);
DataSet dset3 = new DataSet();
da3.Fill(dset3, "RIT");

if (dset.Tables["RIT"].Rows.Count > 0)
{
dataGridView2.DataSource = dset.Tables[0];
dataGridView4.DataSource = dset3.Tables[0];

textBox1.Text = dset3.Tables["NIT"].Rows[0]["Photographs"].ToString();
pictureBox1.Load(Application.StartupPath + "//" + textBox1.Text);

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "NIT", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
}
}






private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)

{
textBox1.Text = Convert.ToString(dataGridView4.CurrentRow.Cells["Photographs"].Value);
}

reply if anybody know the answer
Posted
Updated 23-Jun-15 23:56pm
v2
Comments
Thanks7872 24-Jun-15 2:23am    
What have you tried?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900