Private Sub TblBasicUpgradesDetailDataGridView_RowsAdded(ByVal sender As Object, _
ByVal e As DataGridViewRowsAddedEventArgs) _
Handles TblBasicUpgradesDetailDataGridView.RowsAdded
Dim messageBoxVB As New System.Text.StringBuilder()
messageBoxVB.AppendFormat("{0} = {1}", "sysAppOrder", e.RowIndex)
messageBoxVB.AppendLine()
End Sub
Other related code:Private Sub TblBasicUpgradesDetailDataGridView_UserAddedRow(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles TblBasicUpgradesDetailDataGridView.UserAddedRow
ResetOrdering(e.Row.Index - 1)
End Sub
Private Sub ResetOrdering(ByVal rowIndex As Integer, Optional ByVal forceReorder As Boolean = False)
'Set the sort order column. Once again, not relying on column order but use name
'
Dim rowCount As Integer
Dim rowLocation As Integer
rowCount = TblBasicUpgradesDetailDataGridView.RowCount - 1
rowLocation = rowIndex
If (rowCount - 1 > rowLocation) Then
Dim BasicUpgradesKey As String = BasicUpgradesKeyTextBox.Text
Dim idx As Integer
'
' Create a view with the proper order
'
Dim dataView As New DataView(MpSQLDataSet.Tables("TblBasicUpgradesDetail"), "", "", DataViewRowState.CurrentRows)
dataView.RowFilter = " BasicUpgradesKey = " + BasicUpgradesKey
dataView.Sort = "sysAppOrder"
'
' if we work off the view, it will constantly re-sort. So copy the data into a new table
'
Dim tempTable As DataTable
tempTable = MpSQLDataSet.Tables("TblBasicUpgradesDetail").Clone()
For idx = 0 To dataView.Count - 1
Console.WriteLine(String.Format("{0} {1} {2}", dataView(idx)("sysAppOrder").ToString(), _
dataView(idx)("Description"), idx + 1))
tempTable.ImportRow(dataView(idx).Row)
Next
'
' Loop through the new table and sort it correctly
'
idx = 1
For Each row As DataRow In tempTable.Rows
row("sysAppOrder") = idx
idx += 1
Next
'
' Update the primary table
'
dataView.Sort = String.Empty
For Each row As DataRow In tempTable.Rows
dataView.RowFilter = String.Format("BasicUpgradesDetailKey = {0}", row("BasicUpgradesDetailKey"))
dataView(0)("sysAppOrder") = row("sysAppOrder")
Next
Else
Dim cell As DataGridViewCell
cell = TblBasicUpgradesDetailDataGridView("DataGridViewTextBoxColumn15", rowIndex) '"sysAppOrder"
cell.Value = rowLocation
End If
End Sub
do you set the row numerical order value by yourself?