我有一個DataGridView綁定到一個DataSet。 我只想選擇顯示在DataGridView上的列而不是全部列。 然後我有一個文本框,我想要顯示DataGridView中未顯示的列的值(Version_no列)。這可能嗎?從DataSet中選擇結果
在DataGridView上有一個隱藏的列,並將該值用於文本框會更好嗎?
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
TextBox.Text = MyDataSet.Tables(0).Rows(DGVSearchResults.CurrentRow.Index)(「Software_Version」)從數據集中返回當前的datagridrow。是否有可能從DataGridView中隱藏此列? (或者選擇\僅顯示特定列?)因爲這些在DataGrid中不是必需的,所以它們顯示在文本框中。 – madlan 2010-08-31 22:14:08