Solved

Modify Image column in DataGridView

Posted on 2007-03-28
9
989 Views
Last Modified: 2013-11-07
Hi!

I use a mySQL database from which I populate a DataGridView in my C# .NET applicaiton.
One of the columns contains an image and I wonder if it is possible to modify the content of this column directly in the datagridview? Simply put, I want to select an image cell in the view and get the opportunity to add an image to it or delete an existing image. How do I modify the column (which is autogenerated) to enable this?
0
Comment
Question by:ekberglinda
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:mppeters
ID: 18807569
You'll have to make it not auto-generated I would think and define each column explicitly. There is an ImageField column but I don't think (not entirely sure) it has an edit state, it's only for displaying images. So that means you'll have to use a TemplateField most likely.

<asp:TemplateField HeaderText="Image">
  <itemtemplate>
    <asp:Image id="displayImage" runat="server" ImageUrl='<%# ((System.Data.DataRowView)Container.DataItem)["imagePath"]%>' />
  </itemtemplate>
  <edititemtemplate>
    <asp:FileUpload id="ImageUpload" runat="server" />
  </edititemtemplate>
</asp:TemplateField>

I should warn you, this is going to be very complex because an image upload causes a postback and you're already in a postback state when you click to edit the row. So you're going to have to manually restore the edit state of the row.

Are you sure you want "in grid" editing of these records? From what I remember, it causes enormous viewstates and there's always something that it just won't do. Have you looked at the possibility of having a separate form to edit the records?
0
 

Author Comment

by:ekberglinda
ID: 18807604
It's a Windows application...
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 500 total points
ID: 18814265
If you using vs2003 ...

you can use hitTest to get the current selected cell (it's  very simple),

If you r using 2005, you can try out this to return the selected cell
System.Windows.Forms.DataGridCell selectedCell = dataGrid1.CurrentCell;

 or

privatevoid Select_myDataGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
     string value =  e.Item.Cells[1].Text;
}

You can alway make the dataGrid editable by set some of it property (I don't remeber which one but I bet you can ezly find it)

This is a good example you might wanna look at:
http://www.codeproject.com/dotnet/DataGridEdtAlmostAnythin.asp
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:ekberglinda
ID: 18814455
I have no problem selecting the cell and gettings its value programmatically. What I request is a way to make the cell editable directly in the grid.
0
 
LVL 8

Expert Comment

by:mppeters
ID: 18815746
I believe that is what the code project link she gave you shows. Download the sample code and have a look.
0
 

Author Comment

by:ekberglinda
ID: 18815882
Sorry...missed the link!!! Will look at it and get back to you.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now