Link to home
Start Free TrialLog in
Avatar of netslt
netslt

asked on

MDI Application + Dataset Problem

Hello

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
        frmProductsTreelist.Show()

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"
or
 frmProductsTreelist.TreeList1.PopulateColumns()

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?
Avatar of nickhoggard
nickhoggard

Hi,

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

Cheers

Nick
Avatar of netslt

ASKER

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 ?

Thanks
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.

Cheers

Nick Hoggard
Avatar of netslt

ASKER

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?

Thanks
Avatar of netslt

ASKER

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?
Avatar of netslt

ASKER

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?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of nickhoggard
nickhoggard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of netslt

ASKER

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