c# - DataGridView - Click on Image in Cell and show new Form with full size image -


all: newbie working datagridview1 bound sql server db table via visual studio data sources function. have filled datagrid columns in table, including column containing blobbed image, shows correctly in datagridview slice of image. user able click on datagridview1 cell contains slice of image , launch new form specific image background of (or @ least fill picturebox on same form), can't seem able reference specific image in cell clicked... have tried, unsuccessfully, using "datagridviewimagecolumn" like:

    imagecolumn = new datagridviewimagecolumn();     imagecolumn.image = this.imagedatagridviewimagecolumn.image;     frmpic.backgroundimage = imagecolumn.image; 

can advise correct code use reference specific image?

i think can use datagridview_cellclick event handler,

so can :

 private void datagridview_cellclick(object sender, datagridviewcelleventargs e)  {      // set index pic column, assume pic in column 0     int index = 0;      // check clicked cell right cell     // , every thing okay.      if (datagridview.currentcell.columnindex.equals(index) && e.rowindex != -1)     if (datagridview.currentcell != null && datagridview.currentcell.value != null)     {         // cast image         bitmap img = (bitmap)datagridview.currentcell.value;          // load image data in memory stream         memorystream ms = new memorystream();         img.save(ms, imageformat.jpeg);          // can open image in picbox memory stream.         // if want open pic in other form, need pass memory          // stream form, e.g., in constructor.          // open other form         newform obj = new newform(ms)     }  } 

in newform constructor use memory stream load image in pic box.

 public newform(memorystream ms)  {     picbox.image = image.fromstream(ms);  }  

i hope helps you, luck !


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -