Click here to Skip to main content
15,908,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1-I have add some rows at runtime.
2-Then i have sort ItemCode column using methode
System.ComponentModel.ListSortDirection.Ascending

3-Then I have reorder srNo column as 1,2,3,...
4-Then i read the DataGridView row using for loop.

Then the problem is that i got srNo column cell value 1 but itemCode cell show nothing .

VB
What I have tried:

Dim i As Integer = 0
                        DataGridView2.Sort(DataGridView2.Columns(1), System.ComponentModel.ListSortDirection.Ascending)
                               ReorderSrNo()

For i = 0 To DataGridView2.Rows.Count - 1 ''Add Items To Physical Stock
                            Dim SRno= DataGridView2.Rows(i).Cells(0).Value
                            Dim ItemCode= DataGridView2.Rows(i).Cells(1).Value

Next

Public Sub ReorderSrNo()
        Dim counter As Integer = 0
        For ii As Integer = 0 To DataGridView2.Rows.Count - 1
            DataGridView2.Rows(ii).Cells(0).Value = (System.Math.Max(System.Threading.Interlocked.Increment(counter), counter - 1)).ToString()
        Next
        Dim no As Integer
        no = DataGridView2.Rows.Count
    End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900