Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load Event

Status
Not open for further replies.

kabirpatel

Programmer
Nov 16, 2006
12
GB

Hi all,

I am new to C# windows forms and have a basic question.

I have a form which contains a datagrid. The datagrid is bound to a stored proc that takes 4 parameters.

In the Load event I do a one time initialization of the 4 parameters.

Each of the 4 parameters comes from the selected value of 4 combo boxes.

In the SelectedIndex_Changed event I reset the value of my parameter so that it matches the selected value of the combo box. I then refresh the datagrid.

The problem is that each time the datagrid is refreshed it calls the Load event and all my parameter values are overwirtten with the initialization values.

I know that in ASP.NET there is an IsPostBack property that can be used to determine whether it was the first call to the Load event, but is there something similar in windows forms?

Cheers,
Kabir

 
I think you could add some conditional logic to your load event, to check if something is selected already or not?

Good Luck,

Alex

Ignorance of certain subjects is a great part of wisdom
 
I would suggest writting a sub that will do:

1. Get the new values (ValueMembers) of all the combos.
2. Refresh ..
etc

In each SelectedIndex_Changed call that sub.

____
A better way is - as only one at a time combo will be changed - the sub could take 1 param, that will be the combo whose index was changed. Now you will know which value to get. It is a code optimization
 

Thanks for your advice.

I neded up manually binding the event handler to the event just before the load event had completed and after the data binding had taken place.

i.e I did the following:

this.cmbAreaOfSystem.SelectedIndexChanged += new System.EventHandler(this.cmbAreaOfSystem_SelectedIndexChanged);

and commented it out of the designer.cs file.

This seems to have done the trick.

cheers,
Kabir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top