DataGridView and custom columns
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: DataGridView and custom columns

  1. #1
    Join Date
    Nov 2006
    Posts
    357

    DataGridView and custom columns

    Hey,

    Im currently writing a simple app to display some data from a list of objects. Each object has the following members:

    - ID
    - Name
    - Description
    - Image
    - Value

    Now i want to display Name, Description as normal columns, but i want the Image to display an Image, so ive made an DataGridViewImageColumn, but the problem is that the image member is not enough to load the image. There is a repository which is set within the appconfig that specifies where images should be loaded from, so it would need to load an image from:

    Code:
    string ImageUrl = string.format("{0}/{1}", ConfigurationManager.AppSettings["ImageRepo"], TheCurrentElementsImageMember);
    Hope that makes sense, then the value i would ideally like to display in more custom way adding some styling to the cell and adding some other text in there, alot like the ItemTemplate in ASP...

    Any advice on these topics would be great!

  2. #2
    Join Date
    Nov 2006
    Posts
    357

    Re: DataGridView and custom columns

    Quick bump... incase anyone can one line answer my question

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: DataGridView and custom columns

    I did a DataGridView with a Picture column a while back. All I did was select an 'image' type column from an SQL database as part of my Data Set and attached the Data Set to my DataGridView. It worked fine in that scenario.

    How are you adding the rows to your DataGridView. Are you mapping it to a DataSet?
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  4. #4
    Join Date
    Nov 2006
    Posts
    357

    Re: DataGridView and custom columns

    Hey,

    Adding an DataGridViewImageColumn in is no worries, thats the easy part. The problem i have is that for each row in the table the image needs to take into account the image repository path, so as mentioned before i cant just tell it that the data member is the Image member of the object, as it needs to be prefixed with the AppConfig settings.

    If that makes sense...
    Last edited by Grofit; July 21st, 2009 at 04:25 AM.

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: DataGridView and custom columns

    First try to load the image from the URL you have specified on to a temporary IMAGE type and than add this image to the DatagridviewImage column in the datagrid view.. hope it makes some sense..

  6. #6
    Join Date
    Nov 2006
    Posts
    357

    Re: DataGridView and custom columns

    Each row has a different image though, i read that i should latch onto the CellFormatting event and in there check its the right column and then if its not loaded, load it in there. Still not sure if this will work yet though

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center