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? 1 1966
FYI,
This is in the 1.1 Framework, so ToTable will not work.
Thank you.
"Lyners" wrote: 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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
Is there an event that is invoked when a user sorts a
column in a Windows Forms DataGrid?
I have context senstive icons that are enabled\disabled
depending upon the selected item in the...
|
by: Hardy Wang |
last post by:
Hi,
I have a DataSet, returned by a stored procudure, which has only on
DataTable. At this step there is no sort in DataTable. Is there is a way I
can do to sort DataRows in this DataTable (not...
|
by: Fredrik Rodin |
last post by:
All,
I've been looking around for a solution to my problem for a couple of days
now.
In short, here's my situation:
1.
I'm getting a result from a component back as a datatable and I have...
|
by: Gene Hubert |
last post by:
I'm using the DefaultView from the Datasource for a DataGrid to
present the data in a particular order. It seems that sorting in this
way is an "Active Sort", as is the default sort that is...
|
by: gilly3 |
last post by:
I have a column in a DataView that contains NaN. When I attempt to Sort on
this column, I get:
MESSAGE: Index was outside the bounds of the array.
SOURCE: System.Data
STACKTRACE:
at...
|
by: =?Utf-8?B?UHVjY2E=?= |
last post by:
Are there any good built-in or availble functions that I can call to sort my
dataset datatalbe based on 1 or more of the table's columns?
--
Thanks.
|
by: sklett |
last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I
thought I would post here as well. I hope no one minds too much, if you do
I'm sorry)
I have a DGV that is bound to a...
|
by: Bimal Kothari |
last post by:
private DataTable SortDataTable(DataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Clone();
int rowCount = GetDataTable.Rows.Count;
DataRow foundRows =...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a routine that builds a table using different queries, different SQL
Tables, and adding custom fields.
It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the
table...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |