sort datatable for processing

G

Guest

I am trying to figure out the best way to do this (currently I am having a
problem sorting). I have a vb.net program that contains 2 datagrids on a form
for the end user. When the user is ready to process, behind the scenes, I
combine the 2 datagridas into a datatable, sort and do processing for
creating a load into another system. My problem is that when I combine the
two datagrids into the 1 datatable, I can only sort in a dataview. When I
process the datatable, the table is not sorted. How do I sort a datatable so
I can sequencially process the data after the sort. Below is the current code
I am using to create the table.

Thank you!

Dim numrows As Integer = Datagrid1.DataSource.count
Dim numcols As Integer = Datagrid1.DataSource.table.columns.count
For iloopcounter = 0 To numrows - 1
rownew = AllDataTable.NewRow
For iloopcounter2 = 0 To numcols - 1
If iloopcounter2 = 3 Then ' Determine what the row data type
is
If Datagrid1(iloopcounter, iloopcounter2).ToString <
"5000" Then
multiplier = -1
Else
multiplier = 1
End If
End If
If iloopcounter2 = 7 Then ' Multiple the amount by the
multiplier if column 7
rownew(iloopcounter2) = Str(Val(Datagrid1(iloopcounter,
iloopcounter2) * multiplier))
Else
rownew(iloopcounter2) = Datagrid1(iloopcounter,
iloopcounter2)
End If
Next
AllDataTable.Rows.Add(rownew)
Next

'From Data Area in the 2nd datagrid
Dim numrows2 As Integer = Datagrid2.DataSource.count
Dim numcols2 As Integer = Datagrid2.DataSource.table.columns.count
For iloopcounter = 0 To numrows2 - 1
rownew = AllDataTable.NewRow
For iloopcounter2 = 0 To numcols2 - 1
If iloopcounter2 = 3 Then ' Determine what the row is
If Datagrid2(iloopcounter, iloopcounter2).ToString >
"4999" Then
multiplier = -1
Else
multiplier = 1
End If
End If
If iloopcounter2 = 7 Then ' Multiple the amount by the
multiplier if column 7
rownew(iloopcounter2) = Str(Val(Datagrid2(iloopcounter,
iloopcounter2) * multiplier))
Else
rownew(iloopcounter2) = Datagrid2(iloopcounter,
iloopcounter2)
End If
Next
AllDataTable.Rows.Add(rownew)
Next

AllDataTable.DefaultView.Sort = "column1, column2"

Is there a different way to sort so I can do a sequential processing of the
data table?
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top