Which Form event is triggered first during application startup?

P

Paul Jones

Hi,
which Form event is triggered first during application startup? I need
to load data from a database before RowEnter event of a DataGridView
comes to life. I've put the loading code into Form_Load, but that is not
good enough, because RowEnter is triggered sooner. Hence, an exception
is raised when I try to work with the DataSet, which does not contain
any tables yet.

Thanks for any help.

With regards
Paul Jones.
 
J

JustinBlat

You may want to consider calling a function from the constructor,
before InitializeComponent is called.
 
P

Paul Jones

Justin, thanks for replying...

I'm kind of a newbie, could you please tell me how should I do it
precisely? I piece of code would be great.

Thanks for any further assistance.

With regards
Paul Jones


JustinBlat napsal(a):
 
T

Thomas B

All you need to do is place the code inside the Form constructor, like

public Form1()
{
this.MyDataSet = new DataSet();
... code ...

InitializeComponent();
}

That code will execute before any items inside that form even exist.

/Thomas

Paul Jones skrev:
 
P

Paul Jones

Thomas, thank you very much... I'll try it. Just one other question, can
I use MessageBox.Show() here before InitializeComponent() is executed?

Thanks.

With regards
Paul Jones


Thomas B napsal(a):
 
T

Thomas B

Why don't you try it? ;)
It should work just fine, I've done it in Main() (Program.cs), works
just fine.

Paul Jones skrev:
 
P

Paul Jones

Well, because I'm not able to try it now... :) Nevertheless, you're
right, that was not a good question...

With regards
Paul Jones


Thomas B napsal(a):
 

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