By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Binding Strongly-Typed Collection to a Grid Control

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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)

"Sefa Sevtekin" <se******@de.ibm.com.removeSpam> wrote in message
news:05****************************@phx.gbl...
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

Nov 15 '05 #2

P: n/a
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 ofthe grid.

--
Regards

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

"Sefa Sevtekin" <se******@de.ibm.com.removeSpam> wrote in messagenews:05****************************@phx.gbl...
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

.

Nov 15 '05 #3

P: n/a
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" <se******@de.ibm.com.removeSpam> wrote in message
news:05****************************@phx.gbl...
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

Nov 15 '05 #4

P: n/a

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 [MVP]" <t.********@thona-consulting.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
You dont have to call DataBind on a winform.

--
Regards

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

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:eA****************@tk2msftngp13.phx.gbl...
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" <se******@de.ibm.com.removeSpam> wrote in message
news:05****************************@phx.gbl...
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



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.