Reputation: 61
I am using a DataGridView in my application that contains columns, one of them named ID. I set the ID column to read only. My question is, if I want to add a new record to the DataGridView and the ID column automatically incrementing by 1, how do I do so?
Upvotes: 0
Views: 1324
Reputation: 4313
Your DataGridView is not doing anything on the underlying data. What DataSource do you use? A DataTable (or DataSet of DataTables) can have DataColumns that autoincrement. See more about the DataGridView here
Upvotes: 0
Reputation: 19956
DataColumn, which is used in a DataTable, which is in turn displayed in a DataGridView, has properties for autonumbering.
Please see this cookbok:
or if you want to switch to DataSets, this:
http://msdn.microsoft.com/en-us/library/yctw654b.aspx
Upvotes: 2