2016-04-01 16 views
0

Form1'de (SearchWindow), Form1 (frPlanMain) içinde bulunan bir DataGridView'daki değerleri filtreleyen bir filtre oluşturdum.Form2'den Form1'e DataGridView süzgeç

Object reference not set to an instance of an object.:

sorun

i hata aşağıdaki elde edilmesi.

Sorun şu ki, Form2'deki DataGridView (dGVPlan) yöntemini nasıl kullanacağınızdan emin değilim.

Dize veya benzeri bir şey mi eksik?

Kod için Form1 geçerli:

Imports System.Data.OleDb 

Public Class frPlanMain 

    Public Sub goButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goButton.Click 

     Dim MyPath As String = "D:\" + goTextBox.Text 

     Dim cb As New OleDbConnectionStringBuilder With 
      { 
       .DataSource = MyPath, 
       .Provider = "Microsoft.Jet.OLEDB.4.0" 
      } 
     cb.Add("Extended Properties", "Excel 8.0; IMEX=1; HDR=NO;") 
     Dim cn As New System.Data.OleDb.OleDbConnection With 
      { 
       .ConnectionString = cb.ConnectionString 
      } 
     cn.Open() 
     Dim cmd As OleDbCommand = New OleDbCommand(
      <Statement> 
        SELECT 
         F1 As NrFir, 
         F2 As TechSudura, 
         F3 As TechLP, 
         F4 As HNr, 
         F6 As Sectiune, 
         F7 As Culoare1, 
         F8 As Culoare2, 
         F9 As Lungime, 
         F11 As PozitieStanga, 
         F14 As PozitieDreata, 
         F17 As MSpec, 
         F19 As TerminalSt, 
         F20 As GumitaSt, 
         F21 As TerminalDr, 
         F22 As GumitaDr 
        FROM 
         [WI$] 
       </Statement>.Value, cn) 
     Dim dt As New DataTable 
     dt.Load(cmd.ExecuteReader) 
     cn.Close() 
     dGVPlan.DataSource = dt 

     SearchWindow.Show() 

    End Sub 


End Class 

Kod Form2içindir:

SearchWindow yılında
Public Class SearchWindow 
    Private Sub SearchGoButton_Click(sender As Object, e As EventArgs) Handles SearchGoButton.Click 

     Dim temp As Integer = 0 
     For i As Integer = 0 To frPlanMain.dGVPlan.RowCount - 1 
      For j As Integer = 0 To frPlanMain.dGVPlan.ColumnCount - 1 
       If frPlanMain.dGVPlan.Rows(i).Cells(j).Value.ToString = SearchTextBox.Text Then 
        MsgBox("Item found") 
        temp = 1 
       End If 
      Next 
     Next 
     If temp = 0 Then 
      MsgBox("Item not found") 
     End If 

    End Sub 
End Class 
+1

[bir NullReferenceException nedir ve bunu düzeltmek nasıl?] (Olası yinelenen http://stackoverflow.com/questions/4660142/what- is-a-nullreferenceexception-ve-nasıl-it-fix-it) –

+0

Hangi satırda "Nesne başvurusu bir nesnenin örneğine ayarlanmadı" iletisi oluşur? Hangi şekilde? frPlanMain veya SearchWindow? –

+0

SearchWindow'da gösterilir. –

cevap

0

 Public Property dGVPlan() As DataGridView 
      Get 
      Return _dGVPlan 
      End Get 
      Set 
      _dGVPlan = Value 
      End Set 
    End Property 
    Private _dGVPlan As DataGridView 

frPlanMain

yılında
 cn.Close() 
    dGVPlan.DataSource = dt 
    Dim f As New SearchWindow() 
    f.dGVPlan = frPlanMain.dGVPlan 
    SearchWindow.Show() 

kullanım SearchWindow o ızgara değişken _dGVPlan

 If _dGVPlan.Rows(i).Cells(j).Value.ToString = SearchTextBox.Text Then 
       MsgBox("Item found") 
       temp = 1 
      End If 
+0

Hatayı alıyorum: Dgv, frPlanMain öğesinin bir üyesi değil. F.dGVPlan = frPlanMain.Dgv –

+0

Bu kodun çalışıp çalışmadığını kontrol etmedim, VB dev değil. Her nasılsa düzenlenmiş. :) –

+0

Sorunumu çözmedim :(hala hatayı al. –