DataColumn Class and AutoIncrement

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi all

I have a simple datagrid form which has 4 columns. The first one is used
just like a key and the other threes allow user to enter numbers. The
problem that I am having is that when I click on a cell of a new row but
decide not to enter a value and go back to any of the previous rows for
editting or whatever reason, the value of the new row will be incremented by
value of the AutoIncrementStep

Here is the problem I have

When I loaded the table for a first time, the first row has a value of 0 in
column 1. I then entered 5, 5, 5 in column 2, 3, and 4 respectively. I
clicked on the 2nd row (new row), a new value of 1 was in column 1
(everything is fine up to this point). Instead entering values for column 2,
3 and 4, I went back to my row 1 to edit the data. I then came back to my
second row and enter values for my columns 2, 3 and 4. I noticed that the
value of row 2 is now 2 not 1 and it seems like the number keeps on
incrementing.

Can we make the number increment only when an actual new row is created ? I
have included the code for column 1, all others are pretty much the same.



Dim mInputTable As New DataTable

Dim IDColStyle As New DataGridTextBoxColumn

Dim mIDCol As New DataColumn





'Initialize node column

mIDCol.ColumnName = "Node ID"

mIDCol.Caption = "Node ID"

mIDCol.AutoIncrement = True

mIDCol.AutoIncrementSeed = 0

mIDCol.AutoIncrementStep = 1

mIDCol.DataType = GetType(Integer)





IDColStyle.MappingName = "Node ID"

IDColStyle.NullText = ""

IDColStyle.Width = 72

IDColStyle.ReadOnly = True

IDColStyle.HeaderText = mIDCol.Caption

TableStyle.GridColumnStyles.Add(IDColStyle)



dgdInput.TableStyles.Add(TableStyle)

dgdInput.DataSource = mInputTable
 
Sam,

I dont know why it happens in this case, however in my opinion is what is
the value of an autoincrement number is not important at all.

The value will be setted to a new number at update time, where when other
users has changed as well some row the start point will than be the actual
seed point of the database.

It is good to set the seed, the increment of that and the steps by the way.
And than use -1 for all.

http://msdn.microsoft.com/library/d...stemDataDataColumnClassAutoIncrementTopic.asp

I hope this helps something?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top