Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Stuck here in my project I have topic of airline reservation system in my form1
I am selecting source and destination in two different combobox and I want to show this selected source and destination which is selected by user in next form2 on load in DataGridView1.


(well i am beginner in vb give me hint with small code as example i ll make it in use as per to my project)
Thank you
Posted
Updated 15-Feb-13 0:45am
v2

save value of both combo box in a public String variable
Code on form1 where there are 2 combo box
VB
public strSource as string=""
public strDest as string=""

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

strSource =ComboBox1.Text

End Sub

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

strDest =ComboBox2.Text
 
End Sub

Now on Form2 where there is DataGridView1 write below code on form2 load
VB
DataGridView1.Rows.Add(form1.strSource,form1.strDest)   


i assume there are two coloums in DataGridView1
Happy Coding.....
 
Share this answer
 
v2
Exactly how you do this depends to an extent on how you display the two forms.

If you create the Form2 and display it from your Form1 (on a button click for example) then you can either write a Form2 constructor that accepts the information as parameters and displays it, or you can add public properties to Form2 which display the information. You can then set the information when you create the instance, and before you call ShowDialog.

If you already have Form2 open, created and displayed (via the Show method) from Form1, then create the properties as above and use Form2 instance you displayed to set the display information via those.

If the Form2 is created outside Form1 (by a parent form for example) then the best way is to create an event in Form1 which tells the parent to get the info and pass it to Form2 (again via Form2 properties)
 
Share this answer
 
VB
If Len(Trim(combobx1.Text)) = Len(Trim(combobx2.Text)) Then
    MessageBox.Show("Please select another city", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    combobx2.Focus()
    Exit Sub
End If










this is solution which worked guys thnx for ur support. use this solution if u ant want to have same text value from two combobox to b used
 
Share this answer
 
v3

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