Lloyd Sheen wrote:
Thanks, but I find that I need to get into the datatable and create columns
in the gridview.
<snip>
Oh, I see. We're probably talking about two completely different
controls. For instance, I don't see a *GridView*, here. What I have is
a *DataGridView*, as in the example below.
<code>
'At form level
Private mData As New DataSet
Private Sub Form1_Shown( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles Me.Shown
Using Con As New SqlClient.SqlConnection, _
Cmd As New SqlClient.SqlCommand, _
Bridge As New SqlClient.SqlDataAdapter
Con.ConnectionString = STR_CONNECTION
Con.Open()
Cmd.Connection = Con
Bridge.SelectCommand = Cmd
Cmd.CommandText = SQL_TABLE1
Bridge.Fill(mData, "Table1")
Cmd.CommandText = SQL_TABLE2
Bridge.Fill(mData, "Table2")
Cmd.CommandText = SQL_TABLE3
Bridge.Fill(mData, "Table3")
Con.Close()
End Using
End Sub
Private Sub LSTTables_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles LSTTables.SelectedIndexChanged
Dim Index As Integer = LSTTables.SelectedIndex
If Index >= 0 Then
'Here, it just works...
GRDitems.DataSource = mData.Tables(Index)
End If
End Sub
</code>
In the example above, GRDItems is the DataGridView, and LSTTables is a
combobox with the list of tables I want to select. And it's VB2005...
HTH.
Regards,
Branco.