Generics collection<T> bindinglist<T>

M

Mike Surcouf

Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

Or maybe someone has an easier way

Many Thanks

Mike
 
C

Chris Jobson

Mike Surcouf said:
Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

I think you can use the Collection<T> constructor that takes an IList<T>
parameter, i.e.
gridRows = new BindingList<SalesInvoiceListCompassSelectRow>(rows);

Chris Jobson
 
C

Chris Jobson

Mike Surcouf said:
Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

I think you can use the Collection<T> constructor that takes an IList<T>
parameter, i.e.
gridRows = new BindingList<SalesInvoiceListCompassSelectRow>(rows);

Chris Jobson
 
C

Chris Jobson

Mike Surcouf said:
Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

I think you can use the Collection<T> constructor that takes an IList<T>
parameter, i.e.
gridRows = new BindingList<SalesInvoiceListCompassSelectRow>(rows);

Chris Jobson
 
C

Chris Jobson

Mike Surcouf said:
Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

I think you can use the Collection<T> constructor that takes an IList<T>
parameter, i.e.
gridRows = new BindingList<SalesInvoiceListCompassSelectRow>(rows);

Chris Jobson
 
M

Mike Surcouf

Hi Chris

That worked perfectly thanks a lot.

Mike

Chris Jobson said:
Mike Surcouf said:
Hi All

I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
collection<T> to bindinglist<T>

Sample Code

gridRows = (BindingList<SalesInvoiceListCompassSelectRow>)rows;

Error I get is

Unable to cast object of type
'System.Collections.ObjectModel.Collection`1[CompassEdi.SalesInvoiceListCompassSelectRow]'
to type
'System.ComponentModel.BindingList`1[CompassEdi.SalesInvoiceListCompassSelectRow]'.

Maybe I have to iterate through Collection<T> and add to BindingList<T>.

I think you can use the Collection<T> constructor that takes an IList<T>
parameter, i.e.
gridRows = new BindingList<SalesInvoiceListCompassSelectRow>(rows);

Chris Jobson
 

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