none
auto increment of a table column RRS feed

  • Question

  • I am wanting set the Identity Seed and the Identity Increment in the column properties of a column in a table.  I have a window open for the column properties, but am unable to make any changes to any of the properties.  Obviously the table is disabled.  How do I enable the window?

    gwboolean

    Wednesday, May 16, 2018 2:44 AM

Answers

  • Hi

    Does this small example help?

    ' Form1 default DataGridView1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim MyTable As New DataTable("Freddy")
      Dim BS As New BindingSource
    
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With MyTable
          .Columns.Add(AutoIncColumn)
          .Columns.Add("1", GetType(Integer))
          .Columns.Add("2", GetType(String))
          .Columns.Add("3", GetType(Double))
          .Columns.Add("4", GetType(Boolean))
    
          .Rows.Add(Nothing, 111, "freddy", 1.234, True)
          .Rows.Add(Nothing, 222, "was", 4.321, False)
          .Rows.Add(Nothing, 333, "here", 432.1, True)
        End With
        BS.DataSource = MyTable
        DataGridView1.DataSource = BS
      End Sub
      Function AutoIncColumn() As DataColumn
        Dim c As New DataColumn("ID", GetType(Integer))
        With c
          .ColumnName = "ID"
          .AutoIncrement = True
          .AutoIncrementSeed = 11
          .AutoIncrementStep = 2
        End With
        Return c
      End Function
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by gwboolean Wednesday, May 16, 2018 3:44 AM
    Wednesday, May 16, 2018 3:31 AM

All replies

  • Hi

    Does this small example help?

    ' Form1 default DataGridView1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim MyTable As New DataTable("Freddy")
      Dim BS As New BindingSource
    
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With MyTable
          .Columns.Add(AutoIncColumn)
          .Columns.Add("1", GetType(Integer))
          .Columns.Add("2", GetType(String))
          .Columns.Add("3", GetType(Double))
          .Columns.Add("4", GetType(Boolean))
    
          .Rows.Add(Nothing, 111, "freddy", 1.234, True)
          .Rows.Add(Nothing, 222, "was", 4.321, False)
          .Rows.Add(Nothing, 333, "here", 432.1, True)
        End With
        BS.DataSource = MyTable
        DataGridView1.DataSource = BS
      End Sub
      Function AutoIncColumn() As DataColumn
        Dim c As New DataColumn("ID", GetType(Integer))
        With c
          .ColumnName = "ID"
          .AutoIncrement = True
          .AutoIncrementSeed = 11
          .AutoIncrementStep = 2
        End With
        Return c
      End Function
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by gwboolean Wednesday, May 16, 2018 3:44 AM
    Wednesday, May 16, 2018 3:31 AM
  • What I am trying to do is to be able to set the two properties from the property windows, but cannot because the window with the properties is not enabled.  However, I used a different properties window which allowed me to input the settings.

    Having said that, I like your manual technique there and that is moving into my code snippets as we speak.

    Thanks


    gwboolean

    Wednesday, May 16, 2018 3:43 AM