Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I have MDIform as well as form2 in my project. From MDI, i am opening child form-form2 and populating a richtextbox with a text file content. Also i am populating a listbox on that form.

 

unfortunately i am getting 'Object Reference not set' error on richtextbox loadfile line...

 

 

---menu code that opens form2 and populate richtextbox

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

 

 

StatusBar1.Text = "Ready"

OpenFileDialog1.Filter = "WDL files (*.wdl)|*.txt|All files (*.*)|*.*"

OpenFileDialog1.ShowDialog()

 

Class1.f2.richtextbox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText))

Class1.f2.Show()

StatusBar1.Text = OpenFileDialog1.FileName & " file opened."

 

 

End Sub

 

-----------------------------------

 

 

 

Also how do i add values to the listbox on form2 from mdiform?

I tried- Class1.f2.varlist.Items.Add("test")

unsuccessfull....

 

----my startup is sub_main which shares two forms----

 

Public Class Class1

Public Shared f1 As Form1 = Form1.ActiveForm

Public Shared f2 As Form2

 

Public Shared Sub Main()

f1 = New Form1()

f2 = New Form2()

 

f1.Show()

Application.Run()

End Sub

End Class

----------------------------------------------------------------------

 

 

thanks in advance for any help...

  • 2 weeks later...
Posted

You may have already got your RichTextBox working,

but just in case you are still having problems I thought I'd

let you know what happened when I played around with your code.

 

The code on the MDI Parent Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       f1 = Me
   End Sub

   Private Sub mnuForm2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuForm2.Click
       StatusBar1.Text = "Ready"
       OpenFileDialog1.Filter = "WDL files (*.wdl)|*.txt|All files (*.*)|*.*"
       OpenFileDialog1.ShowDialog()
       f2.rtbTest.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
       f2.Show()
       f2.MdiParent = Me
       StatusBar1.Text = OpenFileDialog1.FileName & " file opened."
   End Sub

   Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
       End
   End Sub

 

I also put the

Public f1 As Form1

Public f2 As New Form2()

into a module instead of a class.

 

If you had got it to work a different way please let me know.

 

ailzaj

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...