forum

Home / DeveloperSection / Forums / Update a listbox from another listbox

Update a listbox from another listbox

Anonymous User 2091 25-Jan-2014

I have two Winforms (admForm and projForm) and each have a listbox. Inside the admForm you can add a user in the list box that belongs to this form.

Everything works fine so far, but I would like to update the listbox in "projForm" with objects that are in the list box in "admForm".

Any idea?

In admForm:

public string ListBox
{
    get { return lstUserOrProject.Items.ToString(); }
}

In projForm:

private void UpdateList()
{
    AdminForm admForm = new AdminForm();
    lstAvailableUser.Items.Add(admForm.ListBox.ToString());
}

Code to open the projForm:

    private void btnAdd_Click(object sender, EventArgs e)
    {
        int index = lstUserOrProject.SelectedIndex;
        switch (cmbUserOrProject.SelectedIndex)
        {
            case (int)UserOrProject.Projects:
                ProjectForm proj = new ProjectForm("Add Project");
                if (proj.ShowDialog() == DialogResult.OK)
                {
                    projMngr.AddProject(proj.ProjectData);
                    UpdateProject();
                }
                break;
            case (int)UserOrProject.Users:
                UserForm user = new UserForm("Add User");
                if (user.ShowDialog() == DialogResult.OK)
                {
                    userMngr.AddUser(user.UserData);
                    UpdateUser();
                }
                break;
        }
    }

c# c# 
Updated on 25-Jan-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By