One of the ways that I have achieved in the past is to use the id property of my list-bound objects.
For example, if I have a BindingList<User> , where the user looks something like this:
public class Names { public string Name { get; set; } public int id { get; set; } }
Then I can link my list as follows:
dataGridView1.AutoGenerateColumns = false; _users = new BindingList<User>(); _users .Add(new Names() { Name = "joe", id=1 }); _users .Add(new Names() { Name = "pete", id = 2 }); bindingSource1.DataSource = _names; DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn(); col1.DataPropertyName = "Name"; dataGridView1.Columns.Add(col1); dataGridView1.DataSource = _users;
Then, when the DataGridView provides a new row, it will have the identifier 0 (the default value for an integer).
Each object that comes from the database has a non-zero identifier.
There might also be a way to achieve this using BindingSources, but I quickly looked through the properties there and nothing came out of me.
David hall
source share