Bizarre OnLoad Behavior with Modal Form

J

John Braganca

I have a modal form that takes a typed dataset and binds some of its
comboboxes to it. Before i call ShowDialog() the dataset is just fine.
In the OnLoad event the dataset is null. This is driving me crazy.
Any help would be greatly appreciated!

Skeleton code below:

class MyForm : System.Windows.Forms.Form
{
protected TypedDataSet ds;
MyForm()
{
myDialog = new MyDialog();
}
override OnLoad(EventArgs e)
{
ds = myDialog.DS = GetDS();
base.OnLoad(e);
}
private void Button_Click(object sender, EventArgs e)
{
//myDialog.DS is not null here
myDialog.ShowDialog(this);
}
}

class MyDialog : System.Winows.Forms.Form
{
public TypedDataSet DS;
override OnLoad(EventArgs e)
{
comboBox1.DataSource = new DataView(DS.Tables[0]); // DS is
null here???
}
}
 
L

Lateralus [MCAD.Net]

John,
I setup something similar to the code you provided. I didn't have a typed
dataset handy so I used just a dataset. I wasn't able to reproduce the
error. Are you sure that the dataset is null? The reason I ask is because
I'm wondering if the DataSet is not null, but there isn't a DataTable at
element 0 of the collection. What is the exact error message you are
getting?
 
J

John Braganca

A System.NullReferenceException. Like I said, the variable holding the
typed dataset becomes null.

Lateralus said:
John,
I setup something similar to the code you provided. I didn't have a typed
dataset handy so I used just a dataset. I wasn't able to reproduce the
error. Are you sure that the dataset is null? The reason I ask is because
I'm wondering if the DataSet is not null, but there isn't a DataTable at
element 0 of the collection. What is the exact error message you are
getting?

--
Lateralus [MCAD.Net]


John Braganca said:
I have a modal form that takes a typed dataset and binds some of its
comboboxes to it. Before i call ShowDialog() the dataset is just fine.
In the OnLoad event the dataset is null. This is driving me crazy.
Any help would be greatly appreciated!

Skeleton code below:

class MyForm : System.Windows.Forms.Form
{
protected TypedDataSet ds;
MyForm()
{
myDialog = new MyDialog();
}
override OnLoad(EventArgs e)
{
ds = myDialog.DS = GetDS();
base.OnLoad(e);
}
private void Button_Click(object sender, EventArgs e)
{
//myDialog.DS is not null here
myDialog.ShowDialog(this);
}
}

class MyDialog : System.Winows.Forms.Form
{
public TypedDataSet DS;
override OnLoad(EventArgs e)
{
comboBox1.DataSource = new DataView(DS.Tables[0]); // DS is
null here???
}
}
 
L

Lateralus [MCAD.Net]

John,
Since I'm unable to reproduce the error, can you zip up your project and
e-mail it to me? If you don't want to that is fine. It is just a bit
difficult trying to debug a problem I can't reproduce.

--
Lateralus [MCAD.Net]


John Braganca said:
A System.NullReferenceException. Like I said, the variable holding the
typed dataset becomes null.

"Lateralus [MCAD.Net]" <dnorm252_at_yahoo.com> wrote in message
John,
I setup something similar to the code you provided. I didn't have a typed
dataset handy so I used just a dataset. I wasn't able to reproduce the
error. Are you sure that the dataset is null? The reason I ask is because
I'm wondering if the DataSet is not null, but there isn't a DataTable at
element 0 of the collection. What is the exact error message you are
getting?

--
Lateralus [MCAD.Net]


John Braganca said:
I have a modal form that takes a typed dataset and binds some of its
comboboxes to it. Before i call ShowDialog() the dataset is just fine.
In the OnLoad event the dataset is null. This is driving me crazy.
Any help would be greatly appreciated!

Skeleton code below:

class MyForm : System.Windows.Forms.Form
{
protected TypedDataSet ds;
MyForm()
{
myDialog = new MyDialog();
}
override OnLoad(EventArgs e)
{
ds = myDialog.DS = GetDS();
base.OnLoad(e);
}
private void Button_Click(object sender, EventArgs e)
{
//myDialog.DS is not null here
myDialog.ShowDialog(this);
}
}

class MyDialog : System.Winows.Forms.Form
{
public TypedDataSet DS;
override OnLoad(EventArgs e)
{
comboBox1.DataSource = new DataView(DS.Tables[0]); // DS is
null here???
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top