Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MDI Application + Dataset Problem

Posted on 2006-07-20
10
Medium Priority
?
270 Views
Last Modified: 2008-01-16
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?
0
Comment
Question by:netslt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 5

Expert Comment

by:nickhoggard
ID: 17144714
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
0
 

Author Comment

by:netslt
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 ?

Thanks
0
 
LVL 5

Expert Comment

by:nickhoggard
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.

Cheers

Nick Hoggard
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:netslt
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?

Thanks
0
 

Author Comment

by:netslt
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?
0
 

Author Comment

by:netslt
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?

Thanks
0
 
LVL 5

Accepted Solution

by:
nickhoggard earned 1000 total points
ID: 17151875
Hi,

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.

Nick
0
 

Author Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

722 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