Help. Getting exception when I rebind grid to another dataset and change column names

A

AboutJAV

Hi,

I am using a datagrid and two dataset with different data. Both views
of the grid contains 5 columns. I toggle between two different views of
the grid which display different types of data. When I toggle, I change
the last 3 columns to different name and bind a different dataset. When
I startup the application, the first dataset when I click on any empty
cells, it works find. However, when I switch for the first time to the
alternative dataset and change the name, it will throw an exception


Index was out of range. Must be non-negative and less than th esize of
the collection.
Parameter name: index


When I keep the column names the same between the two grid views, it
works fine. However, I need to change the column names to indentify the
column type of data.

Any help is appreciated.
 
R

RobinS

1) Are you using the 2003 or 2005 version of VB/C#?
2) Windows Forms or Webforms?

Robin S.
 
R

RobinS

Okay, it's late, I didn't realize this was posted in the
windowsforms ng. Phew.

If you're using the 2005 version, you can put a binding source
between your data source (dataset) and your grid (datagridview).

Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

When you want to change your data source, change the datasource
that is bound to the Binding Source, and the grid will
change automatically. THe binding source is like the glue
between the data source and the grid.

That's my theory, anyway.

Robin S.
-------------------------------------
 
A

AboutJAV

Thanks RobinS,

I forgot to add

Grid.DataBind(DataSet);

after the associating DataSource.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top