
Syntax Form 1
Imports System.IO
imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents btnReferesh As System.Windows.Forms.Button
Friend WithEvents ImageMenu As System.Windows.Forms.ContextMenu
Friend WithEvents mnuImageChange As System.Windows.Forms.MenuItem
Friend WithEvents mnuAddNewImage As System.Windows.Forms.MenuItem
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.btnReferesh = New System.Windows.Forms.Button
Me.ImageMenu = New System.Windows.Forms.ContextMenu
Me.mnuImageChange = New System.Windows.Forms.MenuItem
Me.mnuAddNewImage = New System.Windows.Forms.MenuItem
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Bottom
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(0, 44)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.ReadOnly = True
Me.DataGrid1.Size = New System.Drawing.Size(542, 349)
Me.DataGrid1.TabIndex = 0
'
'btnReferesh
'
Me.btnReferesh.Location = New System.Drawing.Point(12, 12)
Me.btnReferesh.Name = "btnReferesh"
Me.btnReferesh.Size = New System.Drawing.Size(64, 24)
Me.btnReferesh.TabIndex = 1
Me.btnReferesh.Text = "Referesh"
'
'ImageMenu
'
Me.ImageMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuImageChange, Me.mnuAddNewImage})
'
'mnuImageChange
'
Me.mnuImageChange.Index = 0
Me.mnuImageChange.Text = "Change Image"
'
'mnuAddNewImage
'
Me.mnuAddNewImage.Index = 1
Me.mnuAddNewImage.Text = "Add New Image"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(542, 393)
Me.Controls.Add(Me.btnReferesh)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim ItemPicture As System.Windows.Forms.PictureBox
Dim dgCell As DataGridCell
Dim colStyle As GridColumnStylesCollection
Dim dgStyle As New DataGridTableStyle
Dim dgTable As DataGridTextBoxColumn
Dim blnNew As Boolean = False
Dim intRow As Integer, intCol As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
intRow = 0
ItemPicture = New PictureBox
ItemPicture.Width = 148
ItemPicture.Height = 124
ItemPicture.Cursor = System.Windows.Forms.Cursors.Arrow
ItemPicture.Dock = DockStyle.Fill
ItemPicture.SizeMode = PictureBoxSizeMode.StretchImage
AddHandler ItemPicture.Click, AddressOf ClickCBO
RefereshRec()
End Sub
Private Sub ClickCBO(ByVal sender As System.Object, ByVal e As System.EventArgs)
ItemPicture.ContextMenu = (ImageMenu)
End Sub
Private Sub btnReferesh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReferesh.Click
RefereshRec()
End Sub
Private Sub RetreiveImages()
Try
Dim MyData As Byte() = Nothing
Dim crPosition As Integer
crPosition = Me.BindingContext(dt).Position
If blnNew = True Then ItemPicture.Image.Dispose()
blnNew = True
MyData = CType(ds.Tables(0).Rows(crPosition)("ItemPicture"), Byte())
Dim intData As New Integer
intData = MyData.GetUpperBound(0)
Dim fs As New FileStream("c:\tempimage.jpg", FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(MyData, 0, intData)
fs.Close()
MyData = Nothing
ItemPicture.Image = Image.FromFile("c:\tempimage.jpg")
Catch ex As Exception
' MessageBox.Show(ex.Message.ToString)
Finally
cn.Close()
End Try
End Sub
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
RetreiveImages()
End Sub
Private Sub RefereshRec()
cmd.CommandText = "SELECT ItemsID, Item as Item, ItemPicture FROM tblPicture ORDER BY ItemsID"
cmd.CommandType = CommandType.Text
cmd.Connection = cn
da.SelectCommand = cmd
ds.Clear()
da.Fill(ds, "tblPicture")
dt = ds.Tables("tblPicture")
dgStyle.MappingName = dt.TableName
DataGrid1.TableStyles.Add(dgStyle)
dgStyle.PreferredRowHeight = 135
dgStyle.PreferredColumnWidth = 205
colStyle = DataGrid1.TableStyles(0).GridColumnStyles
DataGrid1.DataSource = dt
colStyle(0).Width = 150
colStyle(1).Width = 150
colStyle(2).Width = 150
dgTable = CType(DataGrid1.TableStyles(0).GridColumnStyles(2), DataGridTextBoxColumn)
ItemPicture.Visible = True
ItemPicture.Focus()
dgTable.TextBox.Controls.Add(ItemPicture)
Dim dgCell As DataGridCell
dgCell = New DataGridCell(intRow, 2)
DataGrid1.CurrentCell = dgCell
End Sub
End Class
Syntax Modul Connection
Imports System.Data.OleDb
Module Connection
Public cn As New OleDbConnection
Public cmd As New OleDbCommand
Public da As New OleDbDataAdapter
Public ds As New DataSet
Public dt As DataTable
Public dr As DataRow
Public strFilename As String
Sub main()
Try
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & Application.StartupPath & "\pcDataGrid.mdb"
Application.Run(New Form1)
Catch ex As Exception
End Try
End Sub
End Module
Syntax AssemblyInfo
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
'The following GUID is for the ID of the typelib if this project is exposed to COM
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:

0 komentar:
Posting Komentar