MDI Application + Dataset Problem


I'm reworking an existing (and working) 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?
Who is Participating?

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.


> 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?


netsltAuthor Commented:
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 ?

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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
netsltAuthor Commented:
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?

netsltAuthor Commented:
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?
netsltAuthor Commented:
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?

netsltAuthor Commented:
It was a scoping issue - but took me some time to solve it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.