Tuesday, March 13, 2012

Simple generic list as a datasource for a grid

I'm getting data in a generic list class, which I'm not going to
change. I would like to
use it as a datasource for a datagrid or a gridview, but it doesn't
implement IEnumerable.

I'm wondering if there's a simple technique that would allow me to get
the data into the datagrid.One option is to use the generic BindingList<Tclass.

http://msdn2.microsoft.com/en-us/li...pDownFilterText
"cowznofsky" <jhcorey@.yahoo.comwrote in message
news:1184265867.633987.87780@.57g2000hsv.googlegrou ps.com...

Quote:

Originally Posted by

I'm getting data in a generic list class, which I'm not going to
change. I would like to
use it as a datasource for a datagrid or a gridview, but it doesn't
implement IEnumerable.
>
I'm wondering if there's a simple technique that would allow me to get
the data into the datagrid.
>


On Jul 12, 3:35 pm, "Fred Mertz" <A...@.B.COMwrote:

Quote:

Originally Posted by

One option is to use the generic BindingList<Tclass.
>
http://msdn2.microsoft.com/en-us/li...#Mtps_DropDownF...
>
"cowznofsky" <jhco...@.yahoo.comwrote in message
>
news:1184265867.633987.87780@.57g2000hsv.googlegrou ps.com...
>
>
>

Quote:

Originally Posted by

I'm getting data in a generic list class, which I'm not going to
change. I would like to
use it as a datasource for a datagrid or a gridview, but it doesn't
implement IEnumerable.


>

Quote:

Originally Posted by

I'm wondering if there's a simple technique that would allow me to get
the data into the datagrid.- Hide quoted text -


>
- Show quoted text -


Well, this looked to be just what I needed, but I haven't been able to
get it to work.
In the code below I have my original generic list, myColumns, and my
BindingList, bColumns. I populate bColumns, and I confirm that I can
get a value from the 'DB_Column_Name' property.
Then I try to populate a dropdownlist box. Perhaps I may be using the
wrong syntax here.
But I also try to populate a datagrid, and get an error saying that
'DB_Column_Name' is not found. If I try change the grid to
AutoGenerateColumns="True", it still does not work.

List<MasterColumnRecordmyColumns = wcc.Columns;

BindingList<MasterColumnRecordbColumns = new
BindingList<MasterColumnRecord>();
foreach (MasterColumnRecord mcr in myColumns)
{
bColumns.Add(mcr);
}
string test = bColumns[0].DB_Column_Name;

SortList.DataSource = bColumns;
SortList.DataMember = "DB_Column_Name";
SortList.DataBind();

DataGrid1.DataSource = bColumns;
DataGrid1.DataBind();
On Jul 12, 4:10 pm, cowznofsky <jhco...@.yahoo.comwrote:

Quote:

Originally Posted by

On Jul 12, 3:35 pm, "Fred Mertz" <A...@.B.COMwrote:
>
>
>

Quote:

Originally Posted by

One option is to use the generic BindingList<Tclass.


>

Quote:

Originally Posted by

http://msdn2.microsoft.com/en-us/li...#Mtps_DropDownF...


>

Quote:

Originally Posted by

"cowznofsky" <jhco...@.yahoo.comwrote in message


>

Quote:

Originally Posted by

news:1184265867.633987.87780@.57g2000hsv.googlegrou ps.com...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I'm getting data in a generic list class, which I'm not going to
change. I would like to
use it as a datasource for a datagrid or a gridview, but it doesn't
implement IEnumerable.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I'm wondering if there's a simple technique that would allow me to get
the data into the datagrid.- Hide quoted text -


>

Quote:

Originally Posted by

- Show quoted text -


>
Well, this looked to be just what I needed, but I haven't been able to
get it to work.
In the code below I have my original generic list, myColumns, and my
BindingList, bColumns. I populate bColumns, and I confirm that I can
get a value from the 'DB_Column_Name' property.
Then I try to populate a dropdownlist box. Perhaps I may be using the
wrong syntax here.
But I also try to populate a datagrid, and get an error saying that
'DB_Column_Name' is not found. If I try change the grid to
AutoGenerateColumns="True", it still does not work.
>
List<MasterColumnRecordmyColumns = wcc.Columns;
>
BindingList<MasterColumnRecordbColumns = new
BindingList<MasterColumnRecord>();
foreach (MasterColumnRecord mcr in myColumns)
{
bColumns.Add(mcr);
}
string test = bColumns[0].DB_Column_Name;
>
SortList.DataSource = bColumns;
SortList.DataMember = "DB_Column_Name";
SortList.DataBind();
>
DataGrid1.DataSource = bColumns;
DataGrid1.DataBind();


Ok, I think I see part of my problem. "DB_Column_Name" was a public
varable in the class. When I make it a property, the datagrid bind
works.

0 comments:

Post a Comment