Update LIST<T> from a different form

  • Thread starter Thread starter Vivek
  • Start date Start date
V

Vivek

Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
Currently I have declared the LIST<Role> as public in my parent form. What
can I do to update the <LIST>?

Thanks
 
Vivek,

Why not pass the List<T> to the child form when you create it from the
parent? You can pass it through a constructor, through a property, public
field, or method.

Hope this helps.
 
It sure did. I'll have to find out how to pass the list to the child form.
can you please mention if you know an efficient way.

Thanks


Nicholas Paldino said:
Vivek,

Why not pass the List<T> to the child form when you create it from the
parent? You can pass it through a constructor, through a property, public
field, or method.

Hope this helps.


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

Vivek said:
Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
Currently I have declared the LIST<Role> as public in my parent form.
What can I do to update the <LIST>?

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

| I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
| Currently I have declared the LIST<Role> as public in my parent form.
What
| can I do to update the <LIST>?

I already answered this, here is my reply from the other thread :

////////////////////////////
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
 
Vivek,

Again, why not just call a method on the child form, passing the list to
it? It's like passing a parameter to any other method.

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

Vivek said:
It sure did. I'll have to find out how to pass the list to the child
form. can you please mention if you know an efficient way.

Thanks


Nicholas Paldino said:
Vivek,

Why not pass the List<T> to the child form when you create it from the
parent? You can pass it through a constructor, through a property,
public field, or method.

Hope this helps.


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

Vivek said:
Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM.
Currently I have declared the LIST<Role> as public in my parent form.
What can I do to update the <LIST>?

Thanks
 
I have a class ROLE with all the properties declared. I am adding the roles
to the list
I tried this and gave me an error
*****************************************************
public RoleForm(int RoleID, List<T> lRole)

{

InitializeComponent();

_ID = RoleID;

}

**************************************************************

ERROR:Error 1 The type or namespace name 'T' could not be found (are you
missing a using directive or an assembly reference?)

*****************************************************

Nicholas Paldino said:
Vivek,

Again, why not just call a method on the child form, passing the list
to it? It's like passing a parameter to any other method.

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

Vivek said:
It sure did. I'll have to find out how to pass the list to the child
form. can you please mention if you know an efficient way.

Thanks


Nicholas Paldino said:
Vivek,

Why not pass the List<T> to the child form when you create it from
the parent? You can pass it through a constructor, through a property,
public field, or method.

Hope this helps.


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

Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD
FORM. Currently I have declared the LIST<Role> as public in my parent
form. What can I do to update the <LIST>?

Thanks
 
Vivek,

Unless your class is Generic, you want to do this:

public RoleForm(int RoleId, List<Role> lRole)

By the way, you should not name your parameter lRole, but rather, Roles.
The public naming guidelines indicate that you should do something else.

The reason what I typed works is because when you say List<T>, if T
isn't a type parameter, then the compiler will look for a type named T. You
need to set the specific type for the generic parameter.


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

Vivek said:
I have a class ROLE with all the properties declared. I am adding the roles
to the list
I tried this and gave me an error
*****************************************************
public RoleForm(int RoleID, List<T> lRole)

{

InitializeComponent();

_ID = RoleID;

}

**************************************************************

ERROR:Error 1 The type or namespace name 'T' could not be found (are you
missing a using directive or an assembly reference?)

*****************************************************

Nicholas Paldino said:
Vivek,

Again, why not just call a method on the child form, passing the list
to it? It's like passing a parameter to any other method.

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

Vivek said:
It sure did. I'll have to find out how to pass the list to the child
form. can you please mention if you know an efficient way.

Thanks


in message Vivek,

Why not pass the List<T> to the child form when you create it from
the parent? You can pass it through a constructor, through a property,
public field, or method.

Hope this helps.


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

Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD
FORM. Currently I have declared the LIST<Role> as public in my parent
form. What can I do to update the <LIST>?

Thanks
 
Nicholas, Thanks for your help. I tried renaimg from <T> to <Role> and it
gives me an error

******************************************************
Error 1 Inconsistent accessibility: parameter type
'System.Collections.Generic.List<LPADMIN.Classes.Role>' is less accessible
than method 'LPADMIN.Designer.RoleForm.RoleForm(int,
System.Collections.Generic.List<LPADMIN.Classes.Role>)' D:\Windows
Applications\Agoge\LPADMIN\LPADMIN\Designer\RoleForm.cs 17 16 LPADMIN
*********************************************************************************************************

Can you please help?


Nicholas Paldino said:
Vivek,

Unless your class is Generic, you want to do this:

public RoleForm(int RoleId, List<Role> lRole)

By the way, you should not name your parameter lRole, but rather,
Roles. The public naming guidelines indicate that you should do something
else.

The reason what I typed works is because when you say List<T>, if T
isn't a type parameter, then the compiler will look for a type named T.
You need to set the specific type for the generic parameter.


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

Vivek said:
I have a class ROLE with all the properties declared. I am adding the
roles to the list
I tried this and gave me an error
*****************************************************
public RoleForm(int RoleID, List<T> lRole)

{

InitializeComponent();

_ID = RoleID;

}

**************************************************************

ERROR:Error 1 The type or namespace name 'T' could not be found (are you
missing a using directive or an assembly reference?)

*****************************************************

Nicholas Paldino said:
Vivek,

Again, why not just call a method on the child form, passing the list
to it? It's like passing a parameter to any other method.

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

It sure did. I'll have to find out how to pass the list to the child
form. can you please mention if you know an efficient way.

Thanks


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message Vivek,

Why not pass the List<T> to the child form when you create it from
the parent? You can pass it through a constructor, through a
property, public field, or method.

Hope this helps.


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

Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD
FORM. Currently I have declared the LIST<Role> as public in my parent
form. What can I do to update the <LIST>?

Thanks
 
I think I have figured out what is wrong


Vivek said:
Nicholas, Thanks for your help. I tried renaimg from <T> to <Role> and it
gives me an error

******************************************************
Error 1 Inconsistent accessibility: parameter type
'System.Collections.Generic.List<LPADMIN.Classes.Role>' is less accessible
than method 'LPADMIN.Designer.RoleForm.RoleForm(int,
System.Collections.Generic.List<LPADMIN.Classes.Role>)' D:\Windows
Applications\Agoge\LPADMIN\LPADMIN\Designer\RoleForm.cs 17 16 LPADMIN
*********************************************************************************************************

Can you please help?


Nicholas Paldino said:
Vivek,

Unless your class is Generic, you want to do this:

public RoleForm(int RoleId, List<Role> lRole)

By the way, you should not name your parameter lRole, but rather,
Roles. The public naming guidelines indicate that you should do something
else.

The reason what I typed works is because when you say List<T>, if T
isn't a type parameter, then the compiler will look for a type named T.
You need to set the specific type for the generic parameter.


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

Vivek said:
I have a class ROLE with all the properties declared. I am adding the
roles to the list
I tried this and gave me an error
*****************************************************
public RoleForm(int RoleID, List<T> lRole)

{

InitializeComponent();

_ID = RoleID;

}

**************************************************************

ERROR:Error 1 The type or namespace name 'T' could not be found (are you
missing a using directive or an assembly reference?)

*****************************************************

in message Vivek,

Again, why not just call a method on the child form, passing the
list to it? It's like passing a parameter to any other method.

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

It sure did. I'll have to find out how to pass the list to the child
form. can you please mention if you know an efficient way.

Thanks


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message Vivek,

Why not pass the List<T> to the child form when you create it from
the parent? You can pass it through a constructor, through a
property, public field, or method.

Hope this helps.


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

Hi,

I wish to update the LIST<T> created in PARENT FORM from the CHILD
FORM. Currently I have declared the LIST<Role> as public in my
parent form. What can I do to update the <LIST>?

Thanks
 
Back
Top