Go Premium for a chance to win a PS4. Enter to Win


MDI Application + Dataset Problem

Posted on 2006-07-20
Medium Priority
Last Modified: 2008-01-16

I'm reworking an existing (and working) vb.net application.

Until now I had a TreeList and two Datagrids (plus other stuff) on the same window.

I want to rework that do an MDI application so the user is more free to arrange the above elements/components on his screen (or ist there another solution than MDI to do that).

I have now a main form that opens some MDI forms like this:

Dim frmProductsTreelist As New ProductsTreelist
        frmProductsTreelist.MdiParent = Me

Now I have a problem that I get a (runtime) error when I try to assign a datasource (ds) that has loaded data from an external source and is located in the Main window to the Treelis on the Child Window:

frmProductsTreelist.TreeList1.DataSource = CreateFilteredView(ds.Tables("Categories"), "[f4] = 1")

It also does not work without the FilteredView Part:

frmProductsTreelist.TreeList1.DataSource = ds.Tables("Categories")

Im getting a runtime error that says:

object variable or with block variable not set

Also all other operations that try to do something with the data on the Main Form on one of the Child Forms do not work, like

frmProductsTreelist.TreeList1.KeyFieldName = "f1"

All code listed here is running in the MainForm.

(I'm using Devexpress Components, but I guess that does not matter)

As I said this worked when everything was on the same form/window.

 I'm pretty stuck with my work...

Any ideas?
Question by:netslt
  • 5
  • 3

Expert Comment

ID: 17144714

> It also does not work without the FilteredView Part:
> frmProductsTreelist.TreeList1.DataSource = ds.Tables("Categories")
> Im getting a runtime error that says:
> object variable or with block variable not set

For the above line, if you put a breakpoint on it which of the expressions is 'Nothing'.  Eg, at runtime are either frmProductsTreelist, or frmProductsTreelist.TreeList1 null?



Author Comment

ID: 17146481
I still have a problem here:

 frmProductsTreelist.TreeList1.DataSource = CreateFilteredView(ds.Tables("Categories"), "[f4] = 1")

I tried to get more information, at least I can see that ds has two tables, so the rigth part should be ok.

-      ds.Tables      {System.Data.DataTableCollection}      System.Data.DataTableCollection
      Count      2      Integer
      IsReadOnly      False      Boolean

I see this in the local window:
-      ActiveMdiChild      {oscEditor20.ProductsTreelist}      System.Windows.Forms.Form
-      ActiveControl      {DevExpress.XtraTreeList.TreeList}      System.Windows.Forms.Control

So things seem at least to exist, but I still have no idea why this should not work in an MDI environment when it works on a single form...

Is this the correct way to address components in a child form from an mdi container at all ?


Expert Comment

ID: 17148723
Yeah, your addressing of the item looks ok to me from what you've shown me.

I think we are going to need to cover a little more in the way of information here.

1. Where exactly is the form variable declared.  I assume its on the MDI, but is the declaration against the class or within a method?
2. Where are you making the above call from?  Is it on the MDI or is it on another one of the child forms.
3. Can you write to frmProductsTreelist.Name?
4. Do you have any events declared against frmProductsTreelist.TreeList?

With the error you are showing me, somewhere along the way it is finding something that has not been instantiated correctly.  My thoughts at the moment are that either a) something has gone funny with the declaration of the form, b) the treelist has not been instantiated when you make the call or c) there is an event being handled by your code against the treelist that has a null reference exception being thrown.


Nick Hoggard
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 17150423
1) which variable do you mean exactly?
2) the call is from the MDI parent form
3) I've not yet tried that, but I'm going to and I'll let you know if it works
4) no, besides having placed the treelist component on the child form nothing happens there (up to now)

I wondered if I have to write

frmProductsTreelist.TreeList1.DataSource = CreateFilteredView(ds.Tables("Categories"), "[f4] = 1")

into a function on the child form and then call the function on the main form?


Author Comment

ID: 17150461
Maybe it is a problem that the line

frmProductsTreelist.TreeList1.DataSource = CreateFilteredView(ds.Tables("Categories"), "[f4] = 1")

is within a sub that is declared like this:

   Private Sub CreateCategoriesList(ByVal XMLString As String, ByVal root As String)
frmProductsTreelist.TreeList1.DataSource = CreateFilteredView(ds.Tables("Categories"), "[f4] = 1")
  End Sub

And not within the main part of the MainForm?

Maybe the sub does not know what frmProductsTreelist is?

If yes, how can I make it known to the sub?

Author Comment

ID: 17150475
OK, I've tested

 frmProductsTreelist.Name = "Test"

It works in the main class of Main Form, but it does not work within the sub.

So the problem seems to be as outlined in my previous post, frmProductsTreelist is not known within the sub.

How do i fix that?


Accepted Solution

nickhoggard earned 1000 total points
ID: 17151875

It sounds like a scoping issue to me, but its getting to the point its quite hard to identify the problem without seeing a bit more of the code.

If you can post the designer.vb file and the .vb file for the main form I might be able to spot something, but otherwise I'm sort of out of ideas here sorry.


Author Comment

ID: 17378629
It was a scoping issue - but took me some time to solve it.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question