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!

Textbox wont fill until second load

Status
Not open for further replies.

johnc83

Technical User
Jan 29, 2008
154
GB
Hi all, I have a really annoying problem that I just cannot figure out..

My form have several textboxes including a JobNumberTextBox. When I type in a job number and press enter in this box all the other boxes populate with the details of that job number.

I have a type field in the table which is a combobox on my form. If the job is of type "1" then ALL the details load fine. However if the type is "2" then a couple of the boxes do not populate. If I press enter on the JobNoTextBox again the details are populated.

My form is designed to change depending on what they type is. For example if it type "1" then the Date box may be hidden etc.. and it seems that it is this ChangeScreen procedure that causes the problem even though all that does is hide/move/show boxes. It does nothing with the bindingsources or anything like that.

Does anyone have any ideas as to why this may be happening?

Thanks

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
John:

Can you post code?

I can only guess that you are using ComboBox_SelectedIndexChanged handler
for your code...but I cannot tell.

Also, is this hooked to a SQL DB?

Code would really help.

[code>>Example--SelectedIndexChange]

Private Sub cbVendor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbVendor.SelectedIndexChanged
If Down = True Then
ClearText()
txtVendor.Text = cbVendor.Text

'cbVendor.DroppedDown = True

If txtVendor.Text <> "" Then
Ven = txtVendor.Text
GetData()
End If
'Down = False
Exit Sub
End If
ClearText()
cbVendor.Visible = False
txtVendor.Visible = True
txtVendor.Text = cbVendor.Text
If txtVendor.Text <> "" Then
Ven = txtVendor.Text
GetData()
End If
txtVendor.Focus()
Down = False
End Sub
[/code]

Here is the GetData Procedure referenced:

[code>>GetData]

Sub GetData()

Dim Con As ADODB.Connection
Con = New ADODB.Connection
Dim RS As ADODB.Recordset
RS = New ADODB.Recordset
Dim SQL As String

Ven = Replace(Ven, "'", "''")

Con.ConnectionString = sCon
Con.Open(Con.ConnectionString)
SQL = "Select * from Vendors Where Vendor_Name = '" & Ven & "'"
RS.Open(SQL, Con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockBatchOptimistic, ADODB.CommandTypeEnum.adCmdText)
Do While Not RS.EOF
lID.Text = RS(0).Value
If IsDBNull(RS(3).Value) Then
txtVenSt1.Text = ""
Else
txtVenSt1.Text = RS(3).Value
End If

If IsDBNull(RS(4).Value) Then
txtVenSt2.Text = ""
Else
txtVenSt2.Text = RS(4).Value
End If

If IsDBNull(RS(5).Value) Then
txtVenCity.Text = ""
Else
txtVenCity.Text = RS(5).Value
End If

If IsDBNull(RS(6).Value) Then
txtVenState.Text = ""
Else
txtVenState.Text = RS(6).Value
End If

If IsDBNull(RS(7).Value) Then
txtVenZIP.Text = ""
Else
txtVenZIP.Text = RS(7).Value
End If

If IsDBNull(RS(8).Value) Then
P1.Text = ""
Else
P1.Text = RS(8).Value
End If

If IsDBNull(RS(9).Value) Then
P2.Text = ""
Else
P2.Text = RS(9).Value
End If

If IsDBNull(RS(10).Value) Then
txtVenContact.Text = ""
Else
txtVenContact.Text = RS(10).Value
End If

If IsDBNull(RS(11).Value) Then
txtVenACCT.Text = ""
Else
txtVenACCT.Text = RS(11).Value
End If

lID.Text = RS("Vendor_ID").Value

Exit Do
RS.MoveNext()
Loop
RS.Close()
Con.Close()
RS = Nothing
Con = Nothing
''update
'UpdateVendors()
End Sub
[/code]

Forgive my example...it is very old and not the way I would handle the SQL end anymore.

I hope this helps.


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Hi Ron, thanks for the reply. To be honest I don't think posting code would help (I may be wrong) but this is why I think it..

Lets say my textbox1 is not populating correctly. I delete it completely from my form and then add it again. When I run my app now - textbox2 doesn't work properly. So I delete textbox2 and add from new.

When I run it again textbox3 doesn't work properly.

It's as if someone is sneakily changing stuff behind my back.

p.s. I have comboboxes on my form but it is the textboxes that are playing up.

thanks for the reply.

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
To be honest I don't think posting code would help (I may be wrong) but this is why I think it..
Because unless the IDE is corrupt then it is something about your code that is causing it. Unless you find someone that has had the exact same problem anyone else will want the code so they can possibly get an idea of where to have you start looking for the problem. I myself saw this thread several hours ago and was waiting for your code before I was going to suggest anything. I've played the guessing game too many times, so unless I have a really good idea what I think will fix it often I will wait for the code before giving suggestions.

I admit sometimes I don't think my quest through and forget to post the code or the code seems so large that it isn't a good idea to post. If it is that big then cut some of it out for now. Test the minimum and if it still has a problem then post that.

My form is designed to change depending on what they type is. For example if it type "1" then the Date box may be hidden etc.. and it seems that it is this ChangeScreen procedure that causes the problem even though all that does is hide/move/show boxes.
If you think that is were the problem is then that is were we need to start, but we have to see how you are hiding/moving/showing the boxes.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen, totally understand where you are coming from and thanks for the reply...

The procedure that is causing me problems is as follows:

Code:
 Private Sub ChangeToCleanScreen()
        'Adjust boxes so they reflect the type of service you are creating a job for
        TankStateComboBox.Text = "DIRTY"
        'Hide Lift Buttons/Labels
        OutDriverTextBox.Visible = False
        OutHaulierTextBox.Visible = False
        OutVehicleTextBox.Visible = False
        OutDriverLabel.Visible = False
        OutHaulierLabel.Visible = False
        OutVehicleLabel.Visible = False
        'Hide Heat Buttons/Labels
        MaxTempLabel.Visible = False
        MaxTempTextBox.Visible = False
        RequiredTempLabel.Visible = False
        RequiredTempTextBox.Visible = False
        EndTempTextBox.Visible = False
        EndTempLabel.Visible = False
        StartTempTextBox.Visible = False
        StartTempLabel.Visible = False
        'Modify Print Buttons
        bttnPrint1.Text = "Print Clean Ticket (F9)"
        bttnPrint2.Text = "Print ECD (F10)"
        'Show Clean Buttons/Labels
        'NameOfCleanerTextBox.Visible = True 'not ok
        NameOfCleanerLabel.Visible = True
        OtherTicketNoTextBox.Visible = True 'not ok
        OtherTicketNoLabel.Visible = True
        CheckedByTextBox.Visible = True 'not ok
        CheckedByLabel.Visible = True
        ManlidsLabel.Visible = True
        CompartmentsLabel.Visible = True 
        CompartmentsTextBox.Visible = True 'not ok
        ManlidsTextBox.Visible = True
    End Sub
As you can see I make a few boxes visible and some other ones invisible. The 4 lines with 'not ok' next to them are the ones causing the problem. If any of those lines are included in that procedure then my InHaulierTextBox does not populate on the first asking, everytime after that it works fine though.

You might be right with a corrupt IDE! Hopefully that will point towards a solution..

Thanks a lot

John



.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
First, let me recap to make sure I understand. So from what you said between the two posts if you type in the job number and then select type 1 everything works, but select type 2 and some boxes to not. If you then hit enter on the job number the boxes populate. If you delete the box and re-add it then it works fine, but a new box does not work. All correct?

Now from the final post if you hide those four lines the InHaulierTextBox works, but if they are included it does not update until you go back to the job number box and hit enter. Correct? That sets them to visible so I assume that when those lines are remarked out that those text boxes never show? Have you tried leaving everything visible from start to finish and seen if it functions correctly every time?

You also said that you don't do anything with the binding source. Do you mean that they are not bound or just that even if they are hidden they are still bound?

The InHaulierTextBox isn't listed there so I assume that it is always visible? Not that it should matter (but incase) in the table the data is pulled from does the data for the InHaulierTextBox fall in a column before or after?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen,

your assumptions are correct.

If I don't mess about with making items visible/invisible then the form works perfectly.
All boxes are bound whether they are hidden or not.

My InhaulierTextBox is always visible as it is part of my 'general boxes' but the others such as manlidstextbox are part of my 'varying boxes' and are set as invisible by default until they need to be shown.

If I was to delete m InhaulierTextBox and re-add it then it would work first time but then another one of my boxes wouldn't work.

Thanks for your time on this. I know it is very difficult for you to help in this case because it seems so random.

Thanks again
John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
I've never ran across something like this before. My first assumption is binding as I've only used binding twice and like I said I never had anything like that. That does not mean it has to be the binding though.......Maybe it could be some kind of repaint issue.

Try this as a first guess (if you have not already), have a test button some where on the form and it is set it to display a message box with the Text value of one of the boxes that is not working. That way we could at least rule out a possible repaint issue. If it does show text try running it again with a refresh of that box after the controls are set to visible and see if it will then display.

I had a though for the next step (if not text was showing) and I could have sworn there was a way to tell the binding to refresh all controls bound, but I can't find it now.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top