今天在VB.NET论坛看到有人提出这个问题,我自己也尝试了下,显示图片的代码如下:
'首先要将列的ColumnType设为DataGridViewImageColumn Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load Me.ColTx.ImageLayout = DataGridViewImageCellLayout.Zoom '设置图像布局 End Sub Private Sub DataGridView1_CellFormatting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting '要显示的图像路径 Dim Path As String = "C:/桌面/2.gif" '以文件流的形式读入图像 Dim file As FileStream = New FileStream(Path,FileMode.Open) Dim pic As Image = Image.FromStream(file) file.Close() If e.ColumnIndex = 0 Then e.Value = pic End If End Sub
图片是可以显示,但如果是GIF格式的图像,图像是静止的,不会动,这个问题不知道是什么原因!有待大家研究!