?
Solved

Modify Image column in DataGridView

Posted on 2007-03-28
9
Medium Priority
?
1,007 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 2000 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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