Hi all,
I have got some code i have put together which is three parts there but i am having some problem with the sort aspect of it.
What i am doing is to enable a user to specify in a combobox on a form a threshold (integer). On a button click the code steps through a datatable until the cumilative value of a field in the records row are equal or dont exceed the figure specified. It then selects these rows and presents them in a datgridview in another form. This all works just fine.
What i am struggling with is undertaking a sort on another field before it starts the filter part. It appears to revert to the default order. I know this is me, hence if someone can highlight where im going wrong be most appreciated. Here is my code:
Code:If ComboBox1.Text = "Co2 saving in tonnes" Then Dim table As New DataTable Dim limit As Integer = ComboBox2.Text ' Your threshold Dim r As Integer ' Iterator Dim s As Integer = 0 ' Holds Sum. Change to Decimal or Double if needed. dtOpportunity.DefaultView.Sort = "Payback" table = dtOpportunity For r = 0 To table.Rows.Count - 1 s += CInt(table.Rows(r).Item("Co2Saving")) If s < limit Then newdataTable.Rows.Add(table.Rows(r).ItemArray) Else Exit For End If Next Form9.DataGridView1.DataSource = newdataTable Form9.Show()




Reply With Quote