在DataSet中保存文件的名称就可以了,比如 123.jpg在读取数据的时候,如果需要显示
就在前面加路径 D:\Pic\123.jpg
或者 http://www.123.com/pic/123.jpg

解决方案 »

  1.   

    如果要显示图片,就使用Binding或者自己加一个Label显示就可以了
      

  2.   

    可以写一个继承自DataGridColumnStyle的新样式,重写Paint方法
      

  3.   

    各位Web上的我是会的,关键现在是WindowForm不知道如何做。
    楼主的讲的是有的道理,能有些具体的代码吗,谢谢。
      

  4.   

    示例图片:http://blog.csdn.net/images/blog_csdn_net/langmafeng/71941/t_1.JPG
      

  5.   

    DataGridImageColumnStyle 源码:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Globalization;
    using System.Diagnostics;namespace DataGridExtensions
    {
    /// <summary>
    /// DataGridImageColumnStyle 的摘要说明。
    /// </summary>
    public class DataGridImageColumnStyle : DataGridColumnStyle 
    {
    // UI Constants
    private int              xMargin =           2;
    private int              yMargin =           1;
            
    /// <summary>
    ///   Creates an new DataGridImageColumnStyle
    /// </summary>
    public DataGridImageColumnStyle() 
    {
    } /// <summary>
    ///     Called when the user or the Grid aborts an edit 
    ///     For example hits the Escape key
    /// </summary>
    protected override void Abort(int rowNum) 
    {
    } /// <summary>
    /// Called for the 'from' cell, when the current cell changes. 
    /// This is called whether there are changes to commit or not. 
    /// If the user has not edited the value we simply hide the numericUpDownbox. 
    /// InEdit is used to track whether the cell has been edited or not.
    /// </summary>
    protected override bool Commit(CurrencyManager dataSource, int rowNum) 

    return true;
    } /// <summary>
    ///     Edit is called when a cell column is made the active cell
    ///     We don't put the Grid into edit mode here - we wait for 
    ///     the user to change something before going into edit mode
    ///     because we don't want to dirty the data model unecessarily
    /// </summary>
    protected override void Edit( CurrencyManager source
    , int rowNum
    , Rectangle bounds
    , bool readOnly
    , string instantText
    , bool cellIsVisible

    {
    } /// <summary>
    ///     Called to get the minimum height that rows this column 
    ///     can be
    /// </summary>
    protected override int GetMinimumHeight() 
    {
    return yMargin;
    } /// <summary>
    ///     Called to get the preferred height of the cell 
    ///     
    ///     This called to calculate the preferred height for a row when a 
    ///     row is auto-resized by double-clicking on the row border in 
    ///     the row header 
    ///
    ///     Its also used to paint the parent row when drilled into a child, however 
    ///     in both cases only the width is used never the height
    /// </summary>
    protected override int GetPreferredHeight(Graphics g, object value) 
    {
    return Math.Min(this.GetPreferredSize(g, value).Height, this.GetMinimumHeight());
    } /// <summary>
    ///     Called to get the preferred size of the cell 
    ///     
    ///     This called to calculate the preferred width for a column when a 
    ///     column is auto-resized by double-clicking on the column border in 
    ///     the header 
    ///
    ///     Its also used to paint the parent row when drilled into a child, however 
    ///     in both cases only the width is used never the height
    /// </summary>
    protected override Size GetPreferredSize(Graphics g, object value) 
    {
    int dataGridLineWidth = this.DataGridTableStyle.GridLineStyle == DataGridLineStyle.Solid ? 1 : 0 ;
    string path = value.ToString();
    Image i = Image.FromFile(path); Size preferredSize = new Size(0, 0); preferredSize.Width = xMargin * 2 + dataGridLineWidth + i.Width;
    preferredSize.Height = yMargin + i.Height; return preferredSize;
    } protected override void Paint( Graphics g
    , Rectangle bounds
    , CurrencyManager currencyManager
    , int rowNum
    , Brush backBrush
    , Brush foreBrush
    , bool alignToRight) 
    {
    string path = GetColumnValueAtRow(currencyManager,rowNum).ToString();
    g.DrawImage(Image.FromFile(path), bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel);
    }
           
    /// <summary>
    ///     Paint 2: Called to paint the contents of a particular cell. 
    ///     This simply calls Paint 3.
    /// </summary>
    protected override void Paint( Graphics g
    , Rectangle bounds
    , CurrencyManager currencyManager
    , int rowNum) 
    {
    Paint(g, bounds, currencyManager, rowNum, false);
    } /// <summary>
    ///     Paint 3: Called to paint the contents of a particular cell. 
    ///     This simply calls Paint 1.
    /// </summary>
    protected override void Paint( Graphics g
    , Rectangle bounds
    , CurrencyManager currencyManager
    , int rowNum
    , bool alignToRight) 
    {
    using (Brush backBrush = new SolidBrush(this.DataGridTableStyle.BackColor)) 
    {
    using (Brush foreBrush = new SolidBrush(this.DataGridTableStyle.ForeColor)) 
    {
    Paint(g, bounds, currencyManager, rowNum, backBrush, foreBrush, alignToRight);
    }
    }
    }
    }
    }
      

  6.   

    调用示例:DataGridTableStyle tableStyle = new DataGridTableStyle();DataGridNumericUpDownColumnStyle numCol = new DataGridNumericUpDownColumnStyle();
    numCol.MappingName = "ValueColumn";
    numCol.HeaderText = "ValueColumn";
    numCol.Width = 100;tableStyle.GridColumnStyles.Add(numCol);this.dataGrid1.TableStyles.Add(tableStyle);
      

  7.   

    上面的示范写错了吧,还有这个源码是组件还是控件啊,我没法在VS2003下加入啊,不是类也不是控件和组件,怪了。:O
      

  8.   

    建个空类,然后把代码Copy进去
      

  9.   

    http://blog.csdn.net/images/blog_csdn_net/langmafeng/71941/t_1.JPG你这个的例子能不能让我看看啊,谢谢。