Buttons on Form disabled when using SQL Database

Ok, I've tried de-bugging this and I can't figure out how to rectify my problem.

So far I have a simple application with a simple database. (I'm getting back into programming after 20 years.)

I have a list box with names of historical figures. When you click on the name a picturebox on the form changes to that person's picture and there is a 'summary' text box which says a little about them.

The list box is bound to the database. It works pretty slick actually. The only problem is that once I click on the list box (and the event ListBox1_SelectedIndexChanged takes place) all of the buttons on the form are unresponsive.

Apparently the program goes into a loop where it checks to see if the listbox has changed and continues to do so, going between the database and the ListBox1_SelectedIndexChanged subroutine.

I have tried everything I can think of to break this loop and make the buttons responsive - i.e. go to another form, expand the information, or whatever. Even the 'x' button on the box is disabled.

Funny thing is that as long as I don't click in the list box all the buttons work fine. As soon as I do that's it.

Any suggestions



Answer this question

Buttons on Form disabled when using SQL Database

  • Atiz

    While this is happening, switch to the IDE and choose Debug + Break All. It should stop right away on the statement that is executing. Start single-stepping to see why it is hanging...


  • Wayne Pfeffer

    I'm sorry but you lost me there. Threading or DoEvents

    What I'm seeing is that as soon as I load the Dataset - whether on the Form1 load or when I click on the listbox - the buttons no longer work.

    If I add the following to the subroutine above:

    MeHide()

    Form2.Show()

    It works fine. I click on the name in the box, it quickly loads everything then switches to Form 2. Then I can go back to Form 1 (from a button on Form2) and do it again. It appears that I need some type of code to move it out of that subroutine in order for it to work. I just don't know what kind of code I can put in there.

    I've tried calling some other subs but haven't had much luck.


  • Tadwick

    Also, I tried changing the event from SelectedIndexChanged to Click and it does the same thing.
  • Louis Davidson

    What code do you have in the list boxes click event or SelectedIndexChanged event

  • Cosmin Nicolaescu

    I think I stumbled onto the solution.

    The databinding I used for the list box was SelectedValue = LastName. I changed that property to none then changed the 'Tag' property to InformationBindingSource = LastName.

    This resolved the problem and all my buttons are functioning. I can move ahead now.

    Thanks for trying to help.


  • Barry Kwok

    Thank you for responding. Here is the code:

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    Dim s As String = CType(InformationBindingSource.Current.Row, UnionDataSet.InformationRow).Picture

    Me.PictureBox1.Load(s)

    End Sub

    All this is doing is pulling the location of the picture in the folder and loading it into PictureBox1. As I said before, as long as I don't click on the listbox the buttons will work. As soon as I do it goes to the dataset and retrieves the picture information, comes back and loads the picture just fine. Then it appears to just sit there in the above Sub waiting for another change in the list box. If I click on another name in the box it will go through it again and update, then sit at the end of this statement and wait for another change.


  • soconne

    It is acting normal and you're not hanging anywhere. Are you using threading or DoEvents


  • Buttons on Form disabled when using SQL Database