Adrian
Adrian

Reputation: 61

Automatic Incrementation C#

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

Answers (2)

Christoph Grimmer
Christoph Grimmer

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

Daniel Mošmondor
Daniel Mošmondor

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:

http://www.c-sharpcorner.com/UploadFile/santowebster/AutonumberingDatatable12102008090717AM/AutonumberingDatatable.aspx

or if you want to switch to DataSets, this:

http://msdn.microsoft.com/en-us/library/yctw654b.aspx

Upvotes: 2

Related Questions