TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jay S
NA
230
59.7k
[C#] Access items from Generic List in another Form
Dec 6 2013 8:38 AM
Hi All..
Having some problems trying to do something relatively simple:
Form1:
Opens Form2.
Form2:
Contains some controls for the user to input (textboxes, drop downs etc)
I add these into a list:
namespace Foo
{
public System.Collections.Generic.List<AddPlayerClass> addPlayerList;
public partial class FrmAddPlayer : Form
{
public FrmAddPlayer()
{
//
InitializeComponent();
//
//
//
}
public void addPlayer()
{
this.addPlayerList = new System.Collections.Generic.List<AddPlayerClass>();
//
//
//
addPlayerList.Add(new AddPlayerClass { ID = peopleID,
UID = maxUID,
FirstNameID = Convert.ToInt16(cboPlayerFname.SelectedValue),
SecondNameID = Convert.ToInt16(cboPlayerSname.SelectedValue)
});
//
//
//
}
}
All fine..
I use this class to populate the list:
namespace Foo
{
public class AddPlayerClass
{
//PERSONS DETAILS
public short ID { get; set;}
public int UID { get; set;}
public short FirstNameID {get; set;}
public short SecondNameID {get; set;}
public short CommonNameID {get; set;}
}
}
Again fine.
In From2 I am then calling a Method in Form1, this is done AFTER the list has populated. (list will always only have one item/object in it)
In
Form1
I am trying to access this list so I have done:
Form2 f2 = (Form2)Application.OpenForms["Form2"];
List<AddPlayerClass> addDetails = f2.addPlayerList;
All fine.
When I then do this:
int test = addDetails.ID;
The intellisense can't fine ID as part of the addDetails.
I can't understand what I am doing wrong.
The list will only ever have one object/item in it, all I want to do have access to it.
Reply
Answers (
1
)
Change label text parmanently
Change label text parmanently