R
Ronald S. Cook
Does anyone know why an IEnumerable might not bind to a DataGridView?
Thanks,
Ron
Thanks,
Ron
Nicholas Paldino said:Ron,
Is this in System.Windows.Forms or in ASP.NET? If the answer is the
former, then the requirement is that the collection implement IList, not
IEnumerable. With ASP.NET, I think you ^should^ be able to bind an
IEnumerable to a data source, but you would have to check up on that.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Ronald S. Cook said:Does anyone know why an IEnumerable might not bind to a DataGridView?
Thanks,
Ron
Ronald S. Cook said:Yes, is't a Win Forms app and I can bind other IEnumerables. Just not
sure why not this one. Here it is in case you notice anything:
Public Function GetProgramPriceListByMedicineId(ByVal MedicineId) As
IEnumerable
Dim y As IEnumerable(Of ProgramMedicinePrice)
y = From pmp In dc.ProgramMedicinePrices _
Where pmp.MedicineId = MedicineId
Dim x As IEnumerable
x = From xy In y _
Where xy.ProgramMedicinePriceDate = (From test In y _
Where test.ProgramId =
xy.ProgramId _
Select
test.ProgramMedicinePriceDate).Max _
Select xy.Program.ProgramName, _
xy.ProgramMedicinePriceDate, _
xy.ProgramMedicinePriceDollars
Return x
Nicholas Paldino said:Ron,
Is this in System.Windows.Forms or in ASP.NET? If the answer is the
former, then the requirement is that the collection implement IList, not
IEnumerable. With ASP.NET, I think you ^should^ be able to bind an
IEnumerable to a data source, but you would have to check up on that.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Ronald S. Cook said:Does anyone know why an IEnumerable might not bind to a DataGridView?
Thanks,
Ron
Nicholas Paldino said:Ronald,
Just because it does work doesn't mean that it's designed to work that
way. Ultimately, anything that implements IList is bindable, and that's
the minimum requirement for binding to data in Windows Forms (according to
the framework docs).
So, you will have to make sure that whatever IEnumerable
implementations you have are populated into IList implementations before
binding.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Ronald S. Cook said:Yes, is't a Win Forms app and I can bind other IEnumerables. Just not
sure why not this one. Here it is in case you notice anything:
Public Function GetProgramPriceListByMedicineId(ByVal MedicineId) As
IEnumerable
Dim y As IEnumerable(Of ProgramMedicinePrice)
y = From pmp In dc.ProgramMedicinePrices _
Where pmp.MedicineId = MedicineId
Dim x As IEnumerable
x = From xy In y _
Where xy.ProgramMedicinePriceDate = (From test In y _
Where test.ProgramId
= xy.ProgramId _
Select
test.ProgramMedicinePriceDate).Max _
Select xy.Program.ProgramName, _
xy.ProgramMedicinePriceDate, _
xy.ProgramMedicinePriceDollars
Return x
Nicholas Paldino said:Ron,
Is this in System.Windows.Forms or in ASP.NET? If the answer is the
former, then the requirement is that the collection implement IList, not
IEnumerable. With ASP.NET, I think you ^should^ be able to bind an
IEnumerable to a data source, but you would have to check up on that.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Does anyone know why an IEnumerable might not bind to a DataGridView?
Thanks,
Ron
Ronald S. Cook said:I actually figured it out. I needed to encapsulate the second query in
parentheses and have .ToList() at the end. I guess querying an in-memnroy
object vs querying a database data source was the difference.
Thanks for looking at it.
Nicholas Paldino said:Ronald,
Just because it does work doesn't mean that it's designed to work that
way. Ultimately, anything that implements IList is bindable, and that's
the minimum requirement for binding to data in Windows Forms (according
to the framework docs).
So, you will have to make sure that whatever IEnumerable
implementations you have are populated into IList implementations before
binding.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Ronald S. Cook said:Yes, is't a Win Forms app and I can bind other IEnumerables. Just not
sure why not this one. Here it is in case you notice anything:
Public Function GetProgramPriceListByMedicineId(ByVal MedicineId) As
IEnumerable
Dim y As IEnumerable(Of ProgramMedicinePrice)
y = From pmp In dc.ProgramMedicinePrices _
Where pmp.MedicineId = MedicineId
Dim x As IEnumerable
x = From xy In y _
Where xy.ProgramMedicinePriceDate = (From test In y _
Where test.ProgramId
= xy.ProgramId _
Select
test.ProgramMedicinePriceDate).Max _
Select xy.Program.ProgramName, _
xy.ProgramMedicinePriceDate, _
xy.ProgramMedicinePriceDollars
Return x
in message Ron,
Is this in System.Windows.Forms or in ASP.NET? If the answer is the
former, then the requirement is that the collection implement IList,
not IEnumerable. With ASP.NET, I think you ^should^ be able to bind an
IEnumerable to a data source, but you would have to check up on that.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Does anyone know why an IEnumerable might not bind to a DataGridView?
Thanks,
Ron
returns an implementation that returns an IQueryable implementation, which
^also^ implements IList
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.