VB.NET怎么用代码控制datagridview显示指定的字段?求大神解答
vb.net吧
全部回复
仅看楼主
level 3
鹿封紫0l 楼主
因为我的的OleDbConnection、OleDbCommand一类的全部用的是代码,所以在可视化的VB.NET界面并不能直接显示DATAGRIDVIEW的数据源。可是因为我的数据库中有图片项,不能显示在DATAGRIDVIEW中,而SQL的CommandText属性也不想动。。初学VB.NET 求大神!
2014年11月23日 10点11分 1
level 12
你是要显示图片?
2014年11月23日 11点11分 2
我想把图片在另外一个地方用PICTURE BOX显示,而在DATAGRIDVIEW中不显示
2014年11月24日 11点11分
level 12
数据库里建议只保存图片的物理路径,加载到DataGridView后调用DataGridView的CellFormatting事件进行图片显示处理。
CellFormatting代码如下:
If DataGridView1.Columns(e.ColumnIndex).Name.Equals("Image") Then
Dim path As String = e.Value.ToString()
e.Value = GetImage(path)
End If
GetImage过程代码如下:
Private Function GetImage(ByVal path As String) As System.Drawing.Image
Dim fs As System.IO.FileStream = New System.IO.FileStream(path, System.IO.FileMode.Open)
Dim result As System.Drawing.Image = System.Drawing.Image.FromStream(fs)
fs.Close()
Return result
End Function
2014年11月25日 01点11分 3
谢大神[爱心]
2014年11月25日 13点11分
1