BClaydon
BClaydon

Reputation: 1970

DataGridView not showing all columns in data set

I have a simple Dataset viewer app that shows the contents of a dataset. My dataset has many datatables each with many rows. Unfortunately one of the tables is only showing the first column. When I look at the datatable in the debugger I see all the rows, when it's displayed in the datagridview only the one row. There doesn't seem to be anything weird about the column names.

Here's the code that sets the datagridview:

    ' Load datagrid
    With DataGridViewXml
        .AutoGenerateColumns = True
        .DataSource = ssrsReportDataSet
        .DataMember = ssrsReportDataSet.Tables(0).TableName
    End With

' Table at index 4 is the one losing the columns tableSelecter.SelectedIndex = 4

Here's how I update the view with the table I need:

' Load datagrid
With DataGridViewXml

    .DataMember = ssrsReportDataSet.Tables("MyTable").TableName
End With

Upvotes: 0

Views: 2184

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

Instead of using the DataMember at all, why not do this:

DataGridViewXml.DataSource = ssrsReportDataSet.Tables(0)

and then this:

DataGridViewXml.DataSource = ssrsReportDataSet.Tables("MyTable")

There's no point setting AutoGenerateColumns because it's True by default. You may or may not need to set the DataSource to Nothing and Clear the Columns collection in between.

Upvotes: 2

Related Questions