G
Gerry Viator
Hi all,
Ok I'm starting a new post because I'm stuck. I have included code for a
test datatable
bound to a datagrid. I want after a row is deleted for the AutoIncrement to
start from the last number
there? Not skip numbers. Please help just copy and past over a new
project, the sample will create the controls.
thanks
Gerry
Public Class Form1
Inherits System.Windows.Forms.Form
Friend MainSavedDataTable As New DataTable("Values")
Friend WithEvents Ngrid As New System.Windows.Forms.DataGrid
Friend WithEvents AddRowbtn As New System.Windows.Forms.Button
Friend WithEvents DeleteRowbtn As New System.Windows.Forms.Button
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(274, 268)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Increment Test"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Add(Ngrid)
Me.Controls.Add(AddRowbtn)
Me.Controls.Add(DeleteRowbtn)
Ngrid.DataMember = ""
Ngrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
Ngrid.Location = New System.Drawing.Point(48, 72)
Ngrid.Name = "AutoIncrement Grid test"
Ngrid.Size = New System.Drawing.Size(184, 176)
Ngrid.TabIndex = 0
AddRowbtn.Location = New System.Drawing.Point(24, 32)
AddRowbtn.Name = "AddRowbtn"
AddRowbtn.Size = New System.Drawing.Size(96, 23)
AddRowbtn.TabIndex = 1
AddRowbtn.Text = "Add DataRow"
DeleteRowbtn.Location = New System.Drawing.Point(144, 32)
DeleteRowbtn.Name = "DeleteRowbtn"
DeleteRowbtn.Size = New System.Drawing.Size(104, 23)
DeleteRowbtn.TabIndex = 2
DeleteRowbtn.Text = "Delete DataRow"
Dim i As Integer
Dim CntColumn As New DataColumn("Count")
CntColumn.DataType = GetType(Integer)
CntColumn.AutoIncrement = True
CntColumn.AutoIncrementSeed = -1
CntColumn.AutoIncrementStep = -1
MainSavedDataTable.Columns.Add(CntColumn)
For i = 1 To 5
Dim newRow As DataRow = MainSavedDataTable.NewRow
MainSavedDataTable.Rows.Add(newRow)
Next
MainSavedDataTable.AcceptChanges()
Ngrid.DataSource = MainSavedDataTable
End Sub
Private Sub AddRowbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddRowbtn.Click
Dim newRow As DataRow = MainSavedDataTable.NewRow
MainSavedDataTable.Rows.Add(newRow)
End Sub
Private Sub DeleteRowbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DeleteRowbtn.Click
If MainSavedDataTable.Rows.Count > 1 Then
'Delete last row
Dim Cnt As Integer = MainSavedDataTable.Rows.Count
MainSavedDataTable.Rows(Cnt - 1).Delete()
MainSavedDataTable.AcceptChanges()
End If
End Sub
End Class
Ok I'm starting a new post because I'm stuck. I have included code for a
test datatable
bound to a datagrid. I want after a row is deleted for the AutoIncrement to
start from the last number
there? Not skip numbers. Please help just copy and past over a new
project, the sample will create the controls.
thanks
Gerry
Public Class Form1
Inherits System.Windows.Forms.Form
Friend MainSavedDataTable As New DataTable("Values")
Friend WithEvents Ngrid As New System.Windows.Forms.DataGrid
Friend WithEvents AddRowbtn As New System.Windows.Forms.Button
Friend WithEvents DeleteRowbtn As New System.Windows.Forms.Button
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(274, 268)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Increment Test"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Add(Ngrid)
Me.Controls.Add(AddRowbtn)
Me.Controls.Add(DeleteRowbtn)
Ngrid.DataMember = ""
Ngrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
Ngrid.Location = New System.Drawing.Point(48, 72)
Ngrid.Name = "AutoIncrement Grid test"
Ngrid.Size = New System.Drawing.Size(184, 176)
Ngrid.TabIndex = 0
AddRowbtn.Location = New System.Drawing.Point(24, 32)
AddRowbtn.Name = "AddRowbtn"
AddRowbtn.Size = New System.Drawing.Size(96, 23)
AddRowbtn.TabIndex = 1
AddRowbtn.Text = "Add DataRow"
DeleteRowbtn.Location = New System.Drawing.Point(144, 32)
DeleteRowbtn.Name = "DeleteRowbtn"
DeleteRowbtn.Size = New System.Drawing.Size(104, 23)
DeleteRowbtn.TabIndex = 2
DeleteRowbtn.Text = "Delete DataRow"
Dim i As Integer
Dim CntColumn As New DataColumn("Count")
CntColumn.DataType = GetType(Integer)
CntColumn.AutoIncrement = True
CntColumn.AutoIncrementSeed = -1
CntColumn.AutoIncrementStep = -1
MainSavedDataTable.Columns.Add(CntColumn)
For i = 1 To 5
Dim newRow As DataRow = MainSavedDataTable.NewRow
MainSavedDataTable.Rows.Add(newRow)
Next
MainSavedDataTable.AcceptChanges()
Ngrid.DataSource = MainSavedDataTable
End Sub
Private Sub AddRowbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddRowbtn.Click
Dim newRow As DataRow = MainSavedDataTable.NewRow
MainSavedDataTable.Rows.Add(newRow)
End Sub
Private Sub DeleteRowbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DeleteRowbtn.Click
If MainSavedDataTable.Rows.Count > 1 Then
'Delete last row
Dim Cnt As Integer = MainSavedDataTable.Rows.Count
MainSavedDataTable.Rows(Cnt - 1).Delete()
MainSavedDataTable.AcceptChanges()
End If
End Sub
End Class