I have a form in my vb project (let's call it frm_UpdateDetails). It contains a user control (Let's call it MyUserControl). The user control has several fields that allow the user to edit entries in the database. There is another form (lets say frm_Main) that calls a method in frm_UpdateDetails called ShowUpdateDetails. ShowUpdateDetails does the following

Dim myRtnValue As Boolean

myUserControl.Connect()
myRtnValue = myUserControl.DisplayData()

Me.ShowDialog()

return myRtnValue

This DisplayData takes data that was pulled in from the database and displays it in the appropriate fields. One of these field is a ComboBox called cmbTitle. The cmbTitle.Text gets set to a value from the DataBase.

I can step through the program and see that at the end of DisplayData() it's text property contains the appropriate data but as soon as I call ShowDialog() the Text of the Combo Box blanks out. I can hide the problem by writing my code

Dim myRtnValue As Boolean

myUserControl.Connect()

Me.Show()
Me.Hide()

myRtnValue = myUserControl.DisplayData()

Me.ShowDialog()

return myRtnValue

As long as I have called Show and triggered the form load before calling DisplayData it is ok, but this is not a true fix. I shouldn't have to show and hide my form before setting it's control properties. There is no code in the load event for my form or for my Custom User Control. No other combo boxes on the form lose their value, only this one (Note this is the only combobox that has a DropDown style of Drop Down. The other ComboBoxes are having their text field set implicitly by setting their SelectedValue properties).

Does anyone out there have any thoughts on what would cause this problem? Is it just a glitch with the .net form implementation?

Recommended Answers

All 3 Replies

Did you try?

myRtnValue = myUserControl.DisplayData()
Me.Show()
'Me.Hide()
 ....

I really need to use showdialog for what I am trying to do but, I did actualy try that to see if it was just a problem with ShowDialog. It did not change the results. The Text Property of the ComboBox as set by DisplayData was still set back to an empty string when I called show. I have also checked for code in my load events or visibility changed events. I am not doing anything on either of these events in either the user control or the form. This is a very strange issue.

The code:

Me.Show()
myRtnValue = myUsercontrol.DisplayData()

works but of course I could not do

Me.ShowDialog()
myRtnValue = myUsercontrol.DisplayData()

because then myUsercontrol.DisplayData() doesn't get executed.

Did you try?

myRtnValue = myUserControl.DisplayData()
Me.Show()
'Me.Hide()
 ....

What I need is to Display the data before showing(Show or ShowDialog) it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.