473,480 Members | 4,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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.

Jul 12 '07 #1
3 13918
One option is to use the generic BindingList<Tclass.

http://msdn2.microsoft.com/en-us/lib...DownFilterText

"cowznofsky" <jh*****@yahoo.comwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
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.

Jul 12 '07 #2
On Jul 12, 3:35 pm, "Fred Mertz" <A...@B.COMwrote:
One option is to use the generic BindingList<Tclass.

http://msdn2.microsoft.com/en-us/lib...Mtps_DropDownF...

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

news:11*********************@57g2000hsv.googlegrou ps.com...
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.- 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();

Jul 12 '07 #3
On Jul 12, 4:10 pm, cowznofsky <jhco...@yahoo.comwrote:
On Jul 12, 3:35 pm, "Fred Mertz" <A...@B.COMwrote:
One option is to use the generic BindingList<Tclass.
http://msdn2.microsoft.com/en-us/lib...Mtps_DropDownF...
"cowznofsky" <jhco...@yahoo.comwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
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.- 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();
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.

Jul 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2125
by: Keith R | last post by:
Currently, generic types are not CLS compliant. This puts library authors in a quandry who are faced with three bad alternatives: 1. CLS Compliance but no generics, 2. Using generic types but...
0
7527
by: Tal Sharfi | last post by:
Hi everyone I recently had the need for StringGrid object same as the one that Delphi has. An object that helps show lists of other objects in a simple grid. I searched the news groups and...
3
2362
by: Elliot Rodriguez | last post by:
Hi: I am writing a WinForm app that contains a DataGrid control and a StatusBar control. My goal is to update the status bar using events from a separate class, as well as some other simple...
0
1049
by: guy | last post by:
vb2005 is there a way of assigning multiple collections to be the datasource for a grid? eg suppose i have a database with People and PhoneNumbers tables and a PeoplePhoneNumbers link table ...
25
2993
by: Lars | last post by:
Hi, I have a base class holding a generic list that needs to be accessed by both the base class and its subclasses. What is the best solution to this? I am fairly new to generics, but I am...
0
2891
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
10675
by: Stephen Costanzo | last post by:
I have: Public Class test Private displayValue As String Private dbType As Integer Property Display() As String Get Return displayValue End Get
2
12479
by: ME | last post by:
I have a property that is a generic list of type IAddress (List<IAddress>). When I attempt to view this property using the Property Grid control it plainly says "Collection" and offers the typical...
3
6656
by: dgk | last post by:
I figured that I'd just set the datasource of a gridview to a generic list of classx, but at runtime databind complains: "The data source for GridView with id 'gv1' did not have any properties or...
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.