What is wrong with the below code, when i try to search different names or delete the written name in the textbox, i get the 'Object reference not set to an instance of an object' debug error? I have a textbox, a listbox and a webbrowser object:
Public Class BelgeAra
Dim table As DataTable
Private Sub BelgeAra_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.table = New DataTable
With table.Columns
.Add("Name", GetType(String))
.Add("FullPath", GetType(String))
End With
'Load some data into the table
Me.LoadRows("C:\My Files")
'Bind the table to listbox1
Me.ListBox1.DisplayMember = "Name"
Me.ListBox1.ValueMember = "FullPath"
Me.ListBox1.DataSource = Me.table
End Sub
Private Sub LoadRows(ByVal dir As String)
If IO.Directory.Exists(dir) Then
Try
For Each fn As String In IO.Directory.GetFiles(dir, "*.pdf")
table.Rows.Add(IO.Path.GetFileNameWithoutExtension(fn), fn)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If Me.WebBrowser1.IsBusy Then
Me.WebBrowser1.Stop()
End If
Dim pdf As String = Me.ListBox1.SelectedValue.ToString
Me.WebBrowser1.Navigate(pdf)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim i As Integer = ListBox1.FindString(TextBox1.Text)
ListBox1.SelectedIndex = i
If TextBox1.Text = "" Then
ListBox1.SelectedIndex = -1
End If
End Sub
End Class