  | 
              
	              
	                
  
    |   | 
   
  
    
        
        รบกวนผู้เชี่ยวชาญที่ครับ มันขึ้นว่า  Unhandled exceotion has occurred in your application     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                แก้ไขยังไงหรอครับ 
 
กดคำว่าบันทึกก็ขึ้นคำว่า 
 
Unhandled exceotion has occurred in your application 
 
  
 
 
โค้ดครับ ควรแก้ไขหรือเพิ่มอะไรครับ 
 
Imports System.Drawing.Printing 
Public Class Form2 
    Dim names() As String = {"Microsoft", "Adobe", "SUN"} 
    Dim WithEvents MyPrintDocument As New PrintDocument 
    Private Sub DemoForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        Me.DataGridView1.Columns.Add("เลขทะเบียนรับ1", "เลขทะเบียนรับ") 
        Me.DataGridView1.Columns.Add("เลขแขวงฯ1", "เลขแขวงฯ") 
        Me.DataGridView1.Columns.Add("ที่1", "ที่") 
        Me.DataGridView1.Columns.Add("วันที่1", "วันที่") 
        Me.DataGridView1.Columns.Add("จาก", "จาก") 
        Me.DataGridView1.Columns.Add("ถึง", "ถึง") 
        Me.DataGridView1.Columns.Add("เรื่อง1", "เรื่อง") 
        Me.DataGridView1.Columns.Add("การปฎิบัติ1", "การปฎิบัติ") 
        Me.DataGridView1.Columns.Add("หมายเหตุ1", "หมายเหตุ") 
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 
        DataGridView1.ColumnHeadersHeight = DataGridView1.ColumnHeadersHeight * 2 
        DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter 
    End Sub 
    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting 
        If e.RowIndex = -1 And e.ColumnIndex <> -1 Then 
            e.PaintBackground(e.CellBounds, False) 
            Dim rec As Rectangle = e.CellBounds 
            rec.Y += e.CellBounds.Height / 2 
            rec.Height = e.CellBounds.Height / 2 
            e.PaintContent(rec) 
            e.Handled = True 
        End If 
    End Sub 
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        'TODO: This line of code loads data into the 'Database1DataSet.Table1' table. You can move, or remove it, as needed. 
        Me.Table1TableAdapter.Fill(Me.Database1DataSet.Table1) 
        'TODO: This line of code loads data into the 'Database1DataSet.Table1' table. You can move, or remove it, as needed. 
        Me.Table1TableAdapter.Fill(Me.Database1DataSet.Table1) 
 
    End Sub 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Table1BindingSource.AddNew() 
    End Sub 
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
        Table1BindingSource.RemoveCurrent() 
    End Sub 
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 
        Table1TableAdapter.Update(Database1DataSet.Table1) 
    End Sub 
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
 
    End Sub 
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 
        Table1BindingSource.MovePrevious() 
    End Sub 
 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click 
        Table1BindingSource.MoveNext() 
    End Sub 
 
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 
        Application.Exit() 
    End Sub 
 
    Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged 
        Me.Table1BindingSource.Filter = "เลขทะเบียนรับ like '%" & TextBox10.Text & "%'" 
 
    End Sub 
 
    Private Sub TextBox11_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox11.TextChanged 
        Me.Table1BindingSource.Filter = "เลขแขวงฯ like '%" & TextBox11.Text & "%'" 
    End Sub 
 
    Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged 
        Me.Table1BindingSource.Filter = "เรื่อง like '%" & TextBox12.Text & "%'" 
    End Sub 
 
    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 
        Table1BindingSource.EndEdit() 
        MsgBox("แก้ไขข้อมูลเรียบร้อย", MsgBoxStyle.Information, "แก้ไข") 
    End Sub 
 
    Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        Dim dg As New PrintPreviewDialog 
        dg.Document = MyPrintDocument 
        dg.ShowDialog() 
    End Sub 
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles MyPrintDocument.PrintPage 
        Dim leftMargin As Integer = 10 
        Dim position As Integer = leftMargin 
        Dim yPosition As Integer 
        Dim height As Integer = DataGridView1.ColumnHeadersHeight / 2 
        yPosition = 0 
        For i As Integer = 0 To 5 Step 2 
            Dim totalWidth As Double = DataGridView1.Columns(i).Width + DataGridView1.Columns(i + 1).Width 
            e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(position, yPosition, totalWidth, height)) 
            e.Graphics.DrawRectangle(Pens.Black, New Rectangle(position, yPosition, totalWidth, height)) 
            Dim format As New StringFormat 
            format.Alignment = StringAlignment.Center 
            format.LineAlignment = StringAlignment.Center 
            e.Graphics.DrawString(names(i / 2), New Font("Arial", 12, FontStyle.Bold), Brushes.Black, position, yPosition) 
            position = position + totalWidth 
        Next 
 
        position = leftMargin 
        yPosition = DataGridView1.ColumnHeadersHeight / 2 
        For Each dr As DataGridViewColumn In DataGridView1.Columns 
            Dim totalWidth As Double = dr.Width 
            e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(position, yPosition, totalWidth, height)) 
            e.Graphics.DrawRectangle(Pens.Black, New Rectangle(position, yPosition, totalWidth, height)) 
            e.Graphics.DrawString(dr.HeaderText, New Font("TH NiramitIT๙", 14, FontStyle.Bold), Brushes.Black, position, yPosition) 
            position = position + totalWidth 
        Next 
 
        For Each dr As DataGridViewRow In DataGridView1.Rows 
            position = leftMargin 
            yPosition = yPosition + DataGridView1.ColumnHeadersHeight / 2 
            For Each dc As DataGridViewCell In dr.Cells 
                Dim totalWidth As Double = dc.OwningColumn.Width 
                e.Graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(position, yPosition, totalWidth, height)) 
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(position, yPosition, dc.OwningColumn.Width, height)) 
                e.Graphics.DrawString(dc.Value, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, position, yPosition) 
                position = position + totalWidth 
            Next 
        Next 
    End Sub 
End Class
 
 
  Tag : .NET, Ms Access, MySQL, VB.NET               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2015-01-23 14:52:17	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2015-01-23 14:02:12 | 
                      By :
                          newliiz | 
                      View :
                          876 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 อ้างอิงชื่อ ไม่ถูกน่ะครับ ตรวจสอบชื่อ หรือ index  
 
เช่นมีอยู่ 5 column แต่ไปอ้างอิง column 5 ซึ่ง ต้องอ้างอิง 0 , 1 ,2, 3, 4  คล้ายๆ แบบนี้แหล่ะครับ 
ผิดพลาดประการใดก็ขอโทษด้วยนะครับ ไม่ได้เขียนนานแล้ว                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2015-01-23 14:45:40 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |