By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

how to do datatable without database

P: 3
Expand|Select|Wrap|Line Numbers
  1. ' copy this code in a new proyect
  2.  
  3. Public Class Form1
  4.     WithEvents DataGridView1 As DataGridView, PBX As PictureBox
  5.  
  6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.         Try
  8.             DataGridView1 = New DataGridView
  9.             DataGridView1.Location = New Point(100, 100)
  10.             DataGridView1.Size = New Point(300, 200)
  11.             DataGridView1.Visible = True
  12.             Me.Controls.Add(DataGridView1)
  13.  
  14.             PBX = New PictureBox
  15.             PBX.Location = New Point(420, 100)
  16.             PBX.Size = New Point(200, 200)
  17.             PBX.BorderStyle = BorderStyle.FixedSingle
  18.             PBX.SizeMode = PictureBoxSizeMode.StretchImage
  19.             PBX.Visible = True
  20.             Me.Controls.Add(PBX)
  21.  
  22.             Dim DT(1) As DataTable
  23.  
  24.             DT(1) = New DataTable
  25.             Dim DC As DataColumn
  26.             DC = New DataColumn("Column1", GetType(Object))
  27.  
  28.             DT(1).Columns.Add(DC)
  29.             DC.ColumnName = "A"
  30.  
  31.             DC = New DataColumn("Column2")
  32.             DT(1).Columns.Add(DC)
  33.             DC.ColumnName = "B"
  34.  
  35.             Dim IMG1 As Image = Image.FromFile("C:\MMS FILES\RESOURCES\SCR1.jpg")
  36.             Dim IMG2 As Image = Image.FromFile("C:\MMS FILES\RESOURCES\Perfx.jpg")
  37.  
  38.             DT(1).Rows.Add(IMG1, "222")
  39.             DT(1).Rows.Add(IMG2, "YYY")
  40.  
  41.             DataGridView1.DataSource = DT(1)
  42.  
  43.         Catch ex As Exception
  44.             MsgBox(ex.ToString)
  45.         End Try
  46.  
  47.     End Sub
  48.  
  49.     Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
  50.         On Error Resume Next
  51.         PBX.Image = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
  52.  
  53.     End Sub
  54.  
  55. End Class
Feb 7 '14 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
What is the problem?
What type of application are you working on?
Feb 12 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.