'I need assistance on how to Load the GridView By selecting a value in the ComboBox
1. ComboBox is loaded with Satellite SCC #s' From SQL Server 2005 Express
2. The DatGridView is loaded with signals that correspond to the Transponders on the Satellite From SQL Server Express 2005. The GridView also contains the Satellite SCC #s'.
3. I need the GridView to only load the Signal that Matches the Satellite SCC #s' that are Selected from the ComboBox.
4. So when you click the SCC # in the ComboBox, it will search the Signal Database Table for all the matching
Satellite SCC #s' and then load the signal information into the GridView.
DataBase: SQL Server 2005 express
Language: VB.NET 2005
FrameWork: .NET 2.0
Imports System.Data
Imports System.Data.SqlClient
PublicClass frmCboBoxTest
'Declare Object and Database Connection String
Dim objConnection AsNew SqlConnection _
("server=OFFSITE-223181S\SQLEXPRESS;database=TemDb;Trusted_Connection=yes;")
'SELECT statement for the ComboBox
Dim objDataAdapter2 AsNew SqlDataAdapter( _
"SELECT Satellite.SatelliteSccNum4 From Satellite", objConnection)
'SELECT statement for DataGridView And
'JOIN WHERE Signal Table Transponder ID is Equal to Transponder Table Transponder ID
Dim objDataAdapter AsNew SqlDataAdapter( _
"SELECT * FROM Signal, objConnection)
'ComboBox1 connection Information
Dim objDataSet2 As DataSet
Dim objDataView2 As DataView
'DataGrid connection information
Dim objDataSet As DataSet
Dim objDataView As DataView
PrivateSub FillDataSetAndView()
'ComboBox1
objDataSet2 = New DataSet
objDataView2 = New DataView(objDataSet2.Tables("Satellite"))
'DataGridView
objDataSet = New DataSet
objDataView = New DataView(objDataSet.Tables("Signal"))
'Fill the ComboBox with data
objDataAdapter2.Fill(objDataSet2, "Satellite")
'Fill the DataGrid with data
objDataAdapter.Fill(objDataSet, "Signal")
EndSub
PrivateSub BindFields()
'Clear any previous bindings
ComboBox1.DataBindings.Clear()
grdCboTest.DataBindings.Clear()
'Set the ComboBox properties to bind it to the data and
'Add Satellite SCC #s' from the Satellite DB
ComboBox1.DataSource = objDataSet2.Tables("Satellite")
ComboBox1.DisplayMember = "SatelliteSccNum4"
ComboBox1.ValueMember = "SatelliteSccNum4"
EndSub
PrivateSub ComboBox1_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex Then
'Open the database connection
objConnection.Open()
'Set the DataGridView properties to bind it to the data
grdCboTest.AutoGenerateColumns = True
grdCboTest.DataSource = objDataSet
grdCboTest.DataMember = "Signal"
'Close the Database connection
objConnection.Close()
'Fill the dataset and bind the fields
FillDataSetAndView()
BindFields()
EndIf
EndSub
PrivateSub frmCboBoxTest_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
'Fill ComboBox and DataGridView with data from DB at Load
FillDataSetAndView()
BindFields()
'Set ComboBox Selected index to the 1st position or 0 index at Load
ComboBox1.SelectedIndex = 0
EndSub
PrivateSub btnExit_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Close application when btnExit is Clicked
Me.Close()
EndSub
EndClass
1. ComboBox is loaded with Satellite SCC #s' From SQL Server 2005 Express
2. The DatGridView is loaded with signals that correspond to the Transponders on the Satellite From SQL Server Express 2005. The GridView also contains the Satellite SCC #s'.
3. I need the GridView to only load the Signal that Matches the Satellite SCC #s' that are Selected from the ComboBox.
4. So when you click the SCC # in the ComboBox, it will search the Signal Database Table for all the matching
Satellite SCC #s' and then load the signal information into the GridView.
DataBase: SQL Server 2005 express
Language: VB.NET 2005
FrameWork: .NET 2.0
Imports System.Data
Imports System.Data.SqlClient
PublicClass frmCboBoxTest
'Declare Object and Database Connection String
Dim objConnection AsNew SqlConnection _
("server=OFFSITE-223181S\SQLEXPRESS;database=TemDb;Trusted_Connection=yes;")
'SELECT statement for the ComboBox
Dim objDataAdapter2 AsNew SqlDataAdapter( _
"SELECT Satellite.SatelliteSccNum4 From Satellite", objConnection)
'SELECT statement for DataGridView And
'JOIN WHERE Signal Table Transponder ID is Equal to Transponder Table Transponder ID
Dim objDataAdapter AsNew SqlDataAdapter( _
"SELECT * FROM Signal, objConnection)
'ComboBox1 connection Information
Dim objDataSet2 As DataSet
Dim objDataView2 As DataView
'DataGrid connection information
Dim objDataSet As DataSet
Dim objDataView As DataView
PrivateSub FillDataSetAndView()
'ComboBox1
objDataSet2 = New DataSet
objDataView2 = New DataView(objDataSet2.Tables("Satellite"))
'DataGridView
objDataSet = New DataSet
objDataView = New DataView(objDataSet.Tables("Signal"))
'Fill the ComboBox with data
objDataAdapter2.Fill(objDataSet2, "Satellite")
'Fill the DataGrid with data
objDataAdapter.Fill(objDataSet, "Signal")
EndSub
PrivateSub BindFields()
'Clear any previous bindings
ComboBox1.DataBindings.Clear()
grdCboTest.DataBindings.Clear()
'Set the ComboBox properties to bind it to the data and
'Add Satellite SCC #s' from the Satellite DB
ComboBox1.DataSource = objDataSet2.Tables("Satellite")
ComboBox1.DisplayMember = "SatelliteSccNum4"
ComboBox1.ValueMember = "SatelliteSccNum4"
EndSub
PrivateSub ComboBox1_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex Then
'Open the database connection
objConnection.Open()
'Set the DataGridView properties to bind it to the data
grdCboTest.AutoGenerateColumns = True
grdCboTest.DataSource = objDataSet
grdCboTest.DataMember = "Signal"
'Close the Database connection
objConnection.Close()
'Fill the dataset and bind the fields
FillDataSetAndView()
BindFields()
EndIf
EndSub
PrivateSub frmCboBoxTest_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
'Fill ComboBox and DataGridView with data from DB at Load
FillDataSetAndView()
BindFields()
'Set ComboBox Selected index to the 1st position or 0 index at Load
ComboBox1.SelectedIndex = 0
EndSub
PrivateSub btnExit_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Close application when btnExit is Clicked
Me.Close()
EndSub
EndClass