Solved

Modify Image column in DataGridView

Posted on 2007-03-28
9
990 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

13 Experts available now in Live!

Get 1:1 Help Now