Solved

MDI Application + Dataset Problem

Posted on 2006-07-20
10
248 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
  • 5
  • 3
10 Comments
 
LVL 5

Expert Comment

by:nickhoggard
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:netslt
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:netslt
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
It was a scoping issue - but took me some time to solve it.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now