本文介绍了从一个表单中选择值并在第二个表单上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在我的项目中我在我的表格中有航空预订系统主题1

我在两个不同的组合框中选择源和目的地我希望显示这个选定的来源和目的地是在DataGridView1中加载下一个form2中的用户选择。





(我是vb初学者给我提示小代码作为示例我将根据我的项目使用它)

谢谢

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

推荐答案

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



现在在Form2上有DataGridView1在form2上写下代码加载


Now on Form2 where there is DataGridView1 write below code on form2 load

DataGridView1.Rows.Add(form1.strSource,form1.strDest)   





i假设DataGridView1中有两个coloums

Happy Coding .....



i assume there are two coloums in DataGridView1
Happy Coding.....



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


这篇关于从一个表单中选择值并在第二个表单上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:26