I have a DataGridView bound to a DataSet. I only want a selection of columns displayed on the DataGridView rather than all. I then have a text box which I want to display a value (Version_no column) from the column not showing in the DataGridView. Is this possible?
Would it be better to have a hidden column on the DataGridView and use this value for the text box?
Dim UpdateThreadStart As New ThreadStart(AddressOf QueryDataBase)
Dim CallDataBindToDataGrid As New MethodInvoker(AddressOf Me.DataBindToDataGrid)
Dim MyDataSet As New DataSet
Dim MyDataAdapter As SqlDataAdapter
Dim MyQueryString As String = ""
Dim MyConnection As New SqlConnection("ConnectionString")
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
Try
MyQueryString = "SELECT * FROM TABLE;"
UpdateThread = New Thread(UpdateThreadStart)
UpdateThread.IsBackground = True
UpdateThread.Name = "UpdateThread"
UpdateThread.Start()
While UpdateThread.IsAlive
Application.DoEvents()
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub DataBindToDataGrid()
DGVSearchResults.DataSource = MyDataSet
DGVSearchResults.DataMember = "MyTable"
MyDataAdapter = Nothing
MyDataSet = Nothing
End Sub
' Sub routine used by the background thread to query database.
Public Sub QueryDataBase()
MyDataSet = New DataSet()
MyConnection.Open()
Dim cmd As New SqlCommand(MyQueryString, MyConnection)
MyDataAdapter = New SqlDataAdapter(cmd)
MyDataAdapter.Fill(MyDataSet, "MyTable")
MyConnection.Close()
' Make asynchronous function call to Form's thread.
Me.BeginInvoke(CallDataBindToDataGrid)
End Sub