Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I actually have a form "Commande" and another form and " Détails de commande"
1-the form " Commande " contains additional update buttons, and another button called " Button15 "
2- the form “Détails de commande” contains TextBox1 and TextBox2 and combobox1(for list of product) and textbox5( order quantity)

in the source code as follows:
VB
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        Dim Details_commandes As New Details_commandes
        Details_commandes.TextBox1.Text = TextBox8.Text
        Details_commandes.TextBox2.Text = DateTimePicker1.Text
        Details_commandes.Show()
    End Sub

the button " Button15 " used to take the values of “N°Commande” and that of the “Date de commande” from the form “Commande” and displays them in the form “Détails de commande”.

The problem that when I fill the information of the form ”Commande” (N°Commande,Date de commande, .....) and I click on the “ bouton15” to show the form “Détails de commande” , the combobox1 is empty, but when I reruning the both form I can see the combobox1 with information and I can fill the remaining information for the form “Détails de commande”

[EDITED]
This the code to fill combobox1 in the form "detail de commande":

VB
Private Sub DetailsCommandesF_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
  Dim dr As OleDbDataReader
  CN.Open()
  cmd.Connection = CN
  cmd.CommandText = "select Reference from Produits "
  dr = cmd.ExecuteReader
  Remplir_Liste_Detail_CommandesAF()
  While dr.Read
    ComboBox1.Items.Add(dr.GetValue(0))
  End While
  CN.Close()
Catch ex As Exception
End Try
End Sub
Posted
Updated 28-Jul-15 4:50am
v3
Comments
Leo Chapiro 28-Jul-15 10:01am    
But you don't mention the combobox1 in your source code, where do you fill it?
adoul1 28-Jul-15 10:28am    
this the code to fill combobox1 in the form "detail de commande"
Private Sub DetailsCommandesF_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim dr As OleDbDataReader
CN.Open()
cmd.Connection = CN
cmd.CommandText = "select Reference from Produits "
dr = cmd.ExecuteReader
Remplir_Liste_Detail_CommandesAF()
While dr.Read
ComboBox1.Items.Add(dr.GetValue(0))
End While
CN.Close()
Catch ex As Exception

End Try
End Sub
Richard Deeming 28-Jul-15 10:17am    
Do yourself a favour and give your controls meaningful names.

Sure, you might remember that TextBox42 is "the number of froods" now, but when you come back to your code in a few months, you'll be totally lost.
adoul1 28-Jul-15 10:26am    
thank you for your advice but i will rectify that

1 solution

First off, stop making controls public: it's a very, very poor idea as it "locks" the design of your form so you can't make changes without considering the effect on the outside world. Like (for example) if you decide to use sensible names for your controls to improve readability - you can't any more, because TextBox1 and TextBox2 are being used outside the class. Use a Property instead, and set the text box from that. And to be honest, you REALLY need to think about using proper names! 15 buttons, called 1 to 15? That's very nasty from a maintenance POV.

The next thing is that you don't mention a combobox in that code - so it's possible that you just aren't setting it at all.

Start by using the debugger to "catch" the Shown event of your new form and check what the values look like at that point. If it's empty, then you can start breakpointing what changes it and find out when (or if) that is called.

We can't do any of that for you - we can't run your code! :laugh:
 
Share this answer
 
Comments
adoul1 28-Jul-15 10:38am    
thank you for your advice i rectify what you are said:
Private Sub btnDetail_cmdF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetail_cmdF.Click
Dim DetailsCommandesF As New DetailsCommandesF
DetailsCommandesF.txtnumCmdF.Text = txtDatecmd.Text
DetailsCommandesF.txtDateCmdF.Text = txtDateCmd.Text
DetailsCommandesF.Show()
End Sub
OriginalGriff 28-Jul-15 10:53am    
"stop making controls public"

Was the first thing I said... :sigh:
adoul1 28-Jul-15 10:57am    
i didn't catch what you mean by public, i think i rectify what you said:
i replace this
Details_commandes.TextBox1.Text = TextBox8.Text
Details_commandes.TextBox2.Text = DateTimePicker1.Text

by
DetailsCommandesF.txtnumCmdF.Text = txtDatecmd.Text
DetailsCommandesF.txtDateCmdF.Text = txtDateCmd.Text
OriginalGriff 28-Jul-15 11:06am    
No.
What I mean is that you should not be able to access controls directly from outside the form they are created in.
You are still accessing the textboxes on the DetailsCommandF form from outside the form!

Have a look at this:
http://www.codeproject.com/Tips/548052/Transferring-information-between-two-forms-Part
The code is in C#, but it's pretty clear (just ignore the semicolons and you're pretty much there as VB :laugh: )
Ralf Meier 28-Jul-15 11:37am    
@OG:
my vote of 5 for your suggestion and the comments.
I see it like you - a form is nothing than a special kind of a class. To give information from one class to another, Properties should be used. And also the thing with the Control-Names. As you I think that every control normally has a special function - why don't give it that name ...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900