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.
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.
Comments