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

Reply

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

 
Thread Tools Rate Thread
Old 11-01-2007, 06:40 PM   #1
AboutJAV@gmail.com
Guest
 
Posts: n/a
Default Help. Getting exception when I rebind grid to another dataset and change column names


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.

  Reply With Quote
Old 12-01-2007, 06:36 AM   #2
RobinS
Guest
 
Posts: n/a
Default Re: Help. Getting exception when I rebind grid to another dataset and change column names

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.
>



  Reply With Quote
Old 12-01-2007, 06:39 AM   #3
RobinS
Guest
 
Posts: n/a
Default Re: Help. Getting exception when I rebind grid to another dataset and change column names

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.
>>

>
>



  Reply With Quote
Old 12-01-2007, 04:26 PM   #4
AboutJAV@gmail.com
Guest
 
Posts: n/a
Default Re: Help. Getting exception when I rebind grid to another dataset and change column names

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.
> >>

> >
> >


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off