Solved

Modify Image column in DataGridView

Posted on 2007-03-28
9
995 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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