Binding Strongly-Typed Collection to a Grid Control

  • Thread starter Thread starter Sefa Sevtekin
  • Start date Start date
S

Sefa Sevtekin

I am trying to bind a strongly-typed collection to a data
grid on a windows form like:

BeerInventory inventory = new BeerInventory();
inventory.Add(new Beer
("Hamms", "Hamms Brewing Co.", 3));
inventory.Add(new Beer
("Budweiser", "Anheuser-Busch", 1000));
inventory.Add(new Beer("Mulholland
Rain", "City Brewers", 113));
button1.Text = inventory[1].name;

dataGrid1.DataSource = inventory;

The grid doesn't show the records.Any idea??

Sefa
 
Define "Strongly typed collection". How did you program this?

Otherwise - well - something is wrong with the colleciton OR the setup of
the grid.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
 
Hi Thomas,

Thanks for your reply. Here is my strongly-typed
collection:

public class BeerInventory :
System.Collections.CollectionBase
{

public int Add(Beer value)
{
return List.Add(value);
}

public Beer this[int index]
{
get
{
return (Beer)List[index];
}
set
{
List[index] = value;
}
}
}
I don't think there is a flaw in collection. Anything that
I have to configure on Grid???

Thanks,
Sefa
-----Original Message-----
Define "Strongly typed collection". How did you program this?

Otherwise - well - something is wrong with the colleciton OR the setup of
the grid.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)

I am trying to bind a strongly-typed collection to a data
grid on a windows form like:

BeerInventory inventory = new BeerInventory();
inventory.Add(new Beer
("Hamms", "Hamms Brewing Co.", 3));
inventory.Add(new Beer
("Budweiser", "Anheuser-Busch", 1000));
inventory.Add(new Beer("Mulholland
Rain", "City Brewers", 113));
button1.Text = inventory[1].name;

dataGrid1.DataSource = inventory;

The grid doesn't show the records.Any idea??

Sefa


.
 
Hi ,

It may sound silly, but did you call DataBind() after setting the
DataSource ?
I use a lot of such binding and until now I have never had any problem.

Cheers,
 
Whoops, sorry I did not see that part in the original post , I was thinking
of a asp.net grid :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Thomas Tomicek said:
You dont have to call DataBind on a winform.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)

Ignacio Machin said:
Hi ,

It may sound silly, but did you call DataBind() after setting the
DataSource ?
I use a lot of such binding and until now I have never had any problem.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Sefa Sevtekin said:
I am trying to bind a strongly-typed collection to a data
grid on a windows form like:

BeerInventory inventory = new BeerInventory();
inventory.Add(new Beer
("Hamms", "Hamms Brewing Co.", 3));
inventory.Add(new Beer
("Budweiser", "Anheuser-Busch", 1000));
inventory.Add(new Beer("Mulholland
Rain", "City Brewers", 113));
button1.Text = inventory[1].name;

dataGrid1.DataSource = inventory;

The grid doesn't show the records.Any idea??

Sefa
 
Back
Top