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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox disappearing on windows form

Status
Not open for further replies.

Salte2

Programmer
Nov 5, 2004
17
NO
A ComboBox keeps disappearing on my windows form.
The first time i open the form its there, when i hide it (the form) and open it again, its gone. I guess it has something to do with the datasource it is connected to, but i dont know how to fix it.

When the form is made visible, the following function is executed (only necessary code included):

public void SetVisible(SomeClass s)
{
prog = s; //prog is a variable available in the form-class
my_cbx.DataSource = prog.GetItems() //my_cbx is the combobox
ShowDialog();
}

when the form is closed (hidden) the following funtion is called:

private void CloseForm()
{
prog = null; //this is for safety
Hide();
}

First i thought that the problem was "prog = null;", but even whithout it the same happend. Other comboboxes on the form wich have their items initialized when the form is created don't have this problem. The items of the combobox in question needs to be initialized each time the form is shown, as they will change depending on the object of SomeClass passed on in the SetVisible method.
 
have you tried to use debugging on the prog.GetItems() to see what happens?

set a breakpoint on my_cbx.DataSource = prog.GetItems(); and upon stopping there, use F11 to step into the procedure and see the code. your problem is probably from there.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top