Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi please answer my Question.

How to display image from gridview to picturebox.


private void dataGridView3_MouseDoubleClick(object sender, MouseEventArgs e)
{
  //display image from gridview to picturebox.
}
Posted
Updated 5-Apr-11 18:19pm
v2
Comments
romo22 21-Apr-12 3:15am    
I'm not able to display image from tablegridview to picturebox visual basic 2010 studio. I solve how to reference text value from a cell or from any cell on tablegridview to textbox I created . this the Code for text value " TextBox2.Text = Table1DataGridView.Rows(0).Cells(2).Value.ToString" I tried this code for image but it doesn't work I got error "PictureBox1.image = Table1DataGridView.Rows(0).Cells(2).Value" I hope that you can solve this complex problem and i will be great full for you . thanks Souna mju10ht@gmail.com

You can use CurrentRow[^] to get the information, which row has the focus.

Based on that you can fetch the image from the datasource you have binded to the datagridview.
 
Share this answer
 
I'm not able to display image from tablegridview to picturebox visual basic 2010 studio. I solve how to reference text value from a cell or from any cell on tablegridview to textbox I created . this the Code for text value

VB
TextBox2.Text = Table1DataGridView.Rows(0).Cells(2).Value.ToString



I tried this code for image but it doesn't work I got error
VB
PictureBox1.image = Table1DataGridView.Rows(0).Cells(2).Value



I hope that some one can solve this complex problem and i will be great full for you . thanks Souna mju10ht@gmail.com
 
Share this answer
 
Comments
karthikh87 21-Apr-12 4:36am    
its better to paste full code here so that we can understand well..
saeed1364 21-Apr-12 4:41am    
is very esay.
you use ImageCSharp .aspx
with imagehandler show pic
//// create ImageCSharp .aspx
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class pageadmin_ImageCSharp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["ImageID"] != null)
{

string strQuery = "pleas write query"

String strConnString = System.Configuration.ConfigurationManager

.ConnectionStrings["ConnectionString"].ConnectionString;

SqlCommand cmd = new SqlCommand(strQuery);

cmd.Parameters.Add("@id", SqlDbType.Int).Value

= Convert.ToInt32(Request.QueryString["ImageID"]);

SqlConnection con = new SqlConnection(strConnString);

SqlDataAdapter sda = new SqlDataAdapter();

cmd.CommandType = CommandType.Text;

cmd.Connection = con;

DataTable dt = new DataTable();

try
{

con.Open();

sda.SelectCommand = cmd;

sda.Fill(dt);

}

catch
{

dt = null;

}

finally
{

con.Close();

sda.Dispose();

con.Dispose();

}

if (dt != null)
{

byte[] bytes = (byte[])dt.Rows[0]["FPic"];

Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);

Response.Flush();

Response.End();
// }

}

}

}
}
///////////////////////
but read pic from bank
Image1.ImageUrl = "ImageCSharp.aspx?ImageID=" + reader["please write pimary key from bank to show pic"].ToString();

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