PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Help. Getting exception when I rebind grid to another dataset and change column names
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Help. Getting exception when I rebind grid to another dataset and change column names
![]() |
Help. Getting exception when I rebind grid to another dataset and change column names |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
1) Are you using the 2003 or 2005 version of VB/C#?
2) Windows Forms or Webforms? Robin S. ----------------- <AboutJAV@gmail.com> wrote in message news:1168540806.000517.164140@o58g2000hsb.googlegroups.com... > 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. > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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. ------------------------------------- "RobinS" <RobinS@NoSpam.yah.none> wrote in message news:2JudnenISqX0sTrYnZ2dnUVZ_vmqnZ2d@comcast.com... > 1) Are you using the 2003 or 2005 version of VB/C#? > 2) Windows Forms or Webforms? > > Robin S. > ----------------- > <AboutJAV@gmail.com> wrote in message > news:1168540806.000517.164140@o58g2000hsb.googlegroups.com... >> 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. >> > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Thanks RobinS,
I forgot to add Grid.DataBind(DataSet); after the associating DataSource. Thanks. RobinS wrote: > 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. > ------------------------------------- > "RobinS" <RobinS@NoSpam.yah.none> wrote in message > news:2JudnenISqX0sTrYnZ2dnUVZ_vmqnZ2d@comcast.com... > > 1) Are you using the 2003 or 2005 version of VB/C#? > > 2) Windows Forms or Webforms? > > > > Robin S. > > ----------------- > > <AboutJAV@gmail.com> wrote in message > > news:1168540806.000517.164140@o58g2000hsb.googlegroups.com... > >> 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. > >> > > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

