Solved

Modify Image column in DataGridView

Posted on 2007-03-28
9
991 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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