我尝试创建自定义图片框,我想仅在数据加载到 datagridview 时显示,但不成功。
我做错了什么。这是我的代码的一个例子。
'creating picturebox
pic.CreateControl()
pic.Visible = True
pic.Width = 222
pic.Height = 173
Dim x As Integer = 602
Dim y As Integer = 207
pic.ImageLocation = ("C:\index.jpg")
pic.Load()
pic.Name = "Obavjestenje"
pic.Size = New System.Drawing.Size(264, 200)
pic.TabIndex = 900
pic.TabStop = False
pic.Show()
'filing data into dataset
dsFilter = New DataSet
myCommandLoad = New SqlCommand(workerSQL, conn)
myCommandLoad.CommandTimeout = 200
adapterLoad.SelectCommand = myCommandLoad
adapterLoad.Fill(dsFilter)
adapterLoad.Dispose()
myCommandLoad.Dispose()
' binding dataset and datagrid
If dsFilter.Tables(0).Rows.Count > 0 Then
pic.Dispose()
GridControl1.DataSource = dsFilter.Tables(0)
' at this point I don't whant to see picturebox while my data is uploaded
Pic.Visible = False
End Sub
答案 0 :(得分:1)
尝试
Dim pic As New PictureBox
pic.Width = 222
pic.Height = 173
pic.Location = New Point(?, ?)
pic.ImageLocation = "C:\index.jpg"
pic.Load()
pic.Visible = True
Me.Controls.Add(pic)
pic.Refresh()
'filing data into dataset
...
或更好
Using pic = New PictureBox
pic.Width = 222
pic.Height = 173
pic.Location = New Point(?, ?)
pic.ImageLocation = "C:\index.jpg"
pic.Load()
pic.Visible = True
Me.Controls.Add(pic)
pic.Refresh()
'filing data into dataset
...
...
End Using
最后你不需要pic.Visible = False or dispose
。
瓦尔特