global generic list

V

Vivek

Hi,

I have created a list<t> for my form that displays data in a listview. I
wixh to edit the row with the help of another form and then update the
list<t>. How do I declare a global list that I can use on various forms.

Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

Vivek,

You don't necessarily have to make the variable global in scope. You
could pass the list from one form to another through a property or method or
public field. However, if you really want, you can just declare the list as
static and public, and then any type will have access to that.

Hope this helps.
 
V

Vivek

Thanks. How can I update the LIST once I have updated the values? My target
is to update the database and the list at the same time and then reload my
listview control from LIST.





Nicholas Paldino said:
Vivek,

You don't necessarily have to make the variable global in scope. You
could pass the list from one form to another through a property or method
or public field. However, if you really want, you can just declare the
list as static and public, and then any type will have access to that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vivek said:
Hi,

I have created a list<t> for my form that displays data in a listview. I
wixh to edit the row with the help of another form and then update the
list<t>. How do I declare a global list that I can use on various forms.

Thanks
 
J

Joanna Carter [TeamB]

"Vivek" <[email protected]> a écrit dans le message de (e-mail address removed)...

| Thanks. How can I update the LIST once I have updated the values? My
target
| is to update the database and the list at the same time and then reload my
| listview control from LIST.

If you want to allow full interaction with a list from controls like
DataGridView, etc, then you should create your own generic list class that
implements a couple of interfaces :

GenericList<T> : IList<T>, IBindingList, ICancelAddNew
{
private IList<T> items = new List<T>;

...
}

In implementing this class you can then talk to the database from inside
this list class, intercepting the calls that would normally go straight to a
List<T> and adding your own code to keep the database in sync.

Because of the interfaces implemented, data-aware list controls should
update themselves automatically.

Joanna
 
M

Michael S

Nicholas, Joanna...

Sometimes I think you guys are so helpful that I feel cynic and bitter when
I implement ICompare and foreach you.

Nicholas - Stop spending time on these kind of clueless posts and help where
the action is...You know too much about everything and should focus on the
hard problems. ... which you do great!

Joanna - Rewrite everything you ever written for DM, and your book, to C#
2.0; then ping MSDN Magazine and get yourself a column.. I sure would read
it...

Cheers
- Michael S
 
J

Joanna Carter [TeamB]

"Michael S" <[email protected]> a écrit dans le message de %[email protected]...

| Joanna - Rewrite everything you ever written for DM, and your book, to C#
| 2.0; then ping MSDN Magazine and get yourself a column.. I sure would read
| it...

What is the best way to get in touch with MSDN Magazine ?

Joanna
 
M

Michael S

Joanna Carter said:
"Michael S" <[email protected]> a écrit dans le message de %[email protected]...

| Joanna - Rewrite everything you ever written for DM, and your book, to
C#
| 2.0; then ping MSDN Magazine and get yourself a column.. I sure would
read
| it...

What is the best way to get in touch with MSDN Magazine ?

Joanna

Well, you have several options.

If you want to go hightech you could always use a phone. Or email. If that
is way too complex for you, there is this ROM device called a pencil. It
typically sports fethers and you do it with ink. And there is this device
made out of carbon and parts of a tree, that is actually a kinda RAM. It has
this rubber thingy on that back that makes for rewrites....

As for the editor of MSDN... I have no idea. But I think he (or she) would
be happy if he (or she) got a message saying - I'm freek'n Joanna Carter,
now let me type and then you send me alot of money!

Good luck
- Michael S
 

Ask a Question

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.

Ask a Question

Top