开发者

Create instances of classes that populate forms in Visual Studio

开发者 https://www.devze.com 2023-01-19 14:07 出处:网络
I want to instantiate classes that I have written in Visual Studio 2008 a开发者_运维百科nd then populate a listview with these instances which resides in a form that opens up from within Visual Studio

I want to instantiate classes that I have written in Visual Studio 2008 a开发者_运维百科nd then populate a listview with these instances which resides in a form that opens up from within Visual Studio. To give you an example let's say we have a class Employee within our solution. Using VS Extensibility I would like to open a form in VS that contains a listview. Then I would like to create 100 Employee instances populating the listview and be able to edit their properties. Obviously if I change something in the class Employee e.g: add an attribute date of birth, then the listview will have to be updated. Can anyone provide any examples or links that would be helpful?


Assuming I am uderstanding the question correctly, you have a form with a ListView, and when you open that form on opening it you create 100 instances of employee so first step.

Start with an array list of Employee.

List<Employee> EmployeeList = new List<Employee>();

Populate this list when the form loads.

private void Form1_Load(object sender, System.EventArgs e)
{
    for(int i = 0; i < 100; i++)
    {
       EmployeeList.Items.Add(new Employee());
    }

    // Bind EmployeeList to your ListView
    ListView.ItemSource = EmployeeList;
}

If you update EmployeeList and refresh the listview it should update it with the changed information.

0

精彩评论

暂无评论...
验证码 换一张
取 消