Update datagridview from a WindowForm

Perf

I have this datagridview in a windowform, i do have a button that is supposed to add a new row to the datagridview, so when i click on it it opens up a new window form, how do i save the data from my current window form and update the datagrid view?

The datagrid is populated from a list, like this:

 public void GetUserDetails()
        {   
                        List<xml.UserDescriptor> users = new List<xml.UserDescriptor>();
                        foreach (xml.UserDescriptor dbList in xmlData.Users)
                        {
                            if (dbList.DatabaseDescriptorName == name)
                            {
                                users.Add(new xml.UserDescriptor() { DatabaseDescriptorName = dbList.DatabaseDescriptorName, Username = dbList.Username, Password = dbList.Password, IsAdmin = dbList.IsAdmin });

                            }
                        }

                        dataGridView3.DataSource = users;

            }

How do i save the data i inserted in the new form and after closing it a new row should appear in the datagridview.

Please any help would be appreciated.

kennyzx

Use BindingList<xml.UserDescriptor>, not List<xml.UserDescriptor>.

Pass this users variable to the new Form, and update it within the new Form.

MainForm.cs

new NewForm(users).ShowDialog();

NewForm.cs

public class NewForm : Form
{
    BindingList<xml.UserDescriptor> _users;
    public NewForm(BindingList<xml.UserDescriptor> users)
    {
        _users = users;
    }

    private void btnAddUser_Click(object sender, EventArgs e)
    {
       _users.Add(new xml.UserDescriptor(){...});
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to Update rows of DataGridView from DB Query

From Dev

Error when update data from DataGridView

From Dev

how to update multiple based table from datagridview in wpf

From Dev

C# - Update GUI datagridview from another thread using delegate

From Dev

Insert,Update data in datagridview C# from multiple tables

From Dev

How can I update the DataGridView from a button in another form?

From Dev

How I can update a datagridview for child Form from another datagridview in a parent Form

From Dev

Update DataGridView or update the binded DataSource?

From Dev

Thread to update DataGridView

From Dev

DataGridView will not update correctly

From Dev

Automatically update a datagridview

From Dev

Read XML and update DataGridView

From Dev

EF 4.0 Datagridview not update

From Dev

update DataGridView column value

From Dev

Entity Framework 6 uses an UPDATE when it should be using a DELETE when deleting from a bound DataGridView

From Dev

Repopulate Combobox after datagridview update

From Dev

Update Counter not updating my DataGridView

From Dev

update data in datagridview on new form

From Dev

How to Update data in the dataGridview ONLY

From Dev

Update Counter not updating my DataGridView

From Dev

Update each selected datagridview rows

From Dev

Why wont DataGridView Update Database?

From Dev

datagridview update row to csv file

From Dev

Sql update makes datagridview disappear

From Dev

DateTimePicker value from DataGridView

From Dev

DatagridView not loading from DataTable

From Dev

Filtring/Searching from a DataGridView

From Dev

Filling DataGridView from BackgroundWorker

From Dev

Calculate From DataGridView

Related Related

HotTag

Archive