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.DataS ource.count
Dim numcols As Integer = Datagrid1.DataS ource.table.col umns.count
For iloopcounter = 0 To numrows - 1
rownew = AllDataTable.Ne wRow
For iloopcounter2 = 0 To numcols - 1
If iloopcounter2 = 3 Then ' Determine what the row data type
is
If Datagrid1(iloop counter, 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(iloopcou nter2) = Str(Val(Datagri d1(iloopcounter ,
iloopcounter2) * multiplier))
Else
rownew(iloopcou nter2) = Datagrid1(iloop counter,
iloopcounter2)
End If
Next
AllDataTable.Ro ws.Add(rownew)
Next
'From Data Area in the 2nd datagrid
Dim numrows2 As Integer = Datagrid2.DataS ource.count
Dim numcols2 As Integer = Datagrid2.DataS ource.table.col umns.count
For iloopcounter = 0 To numrows2 - 1
rownew = AllDataTable.Ne wRow
For iloopcounter2 = 0 To numcols2 - 1
If iloopcounter2 = 3 Then ' Determine what the row is
If Datagrid2(iloop counter, 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(iloopcou nter2) = Str(Val(Datagri d2(iloopcounter ,
iloopcounter2) * multiplier))
Else
rownew(iloopcou nter2) = Datagrid2(iloop counter,
iloopcounter2)
End If
Next
AllDataTable.Ro ws.Add(rownew)
Next
AllDataTable.De faultView.Sort = "column1, column2"
Is there a different way to sort so I can do a sequential processing of the
data table? 1 1976
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.DataS ource.count Dim numcols As Integer = Datagrid1.DataS ource.table.col umns.count For iloopcounter = 0 To numrows - 1 rownew = AllDataTable.Ne wRow For iloopcounter2 = 0 To numcols - 1 If iloopcounter2 = 3 Then ' Determine what the row data type is If Datagrid1(iloop counter, 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(iloopcou nter2) = Str(Val(Datagri d1(iloopcounter , iloopcounter2) * multiplier)) Else rownew(iloopcou nter2) = Datagrid1(iloop counter, iloopcounter2) End If Next AllDataTable.Ro ws.Add(rownew) Next
'From Data Area in the 2nd datagrid Dim numrows2 As Integer = Datagrid2.DataS ource.count Dim numcols2 As Integer = Datagrid2.DataS ource.table.col umns.count For iloopcounter = 0 To numrows2 - 1 rownew = AllDataTable.Ne wRow For iloopcounter2 = 0 To numcols2 - 1 If iloopcounter2 = 3 Then ' Determine what the row is If Datagrid2(iloop counter, 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(iloopcou nter2) = Str(Val(Datagri d2(iloopcounter , iloopcounter2) * multiplier)) Else rownew(iloopcou nter2) = Datagrid2(iloop counter, iloopcounter2) End If Next AllDataTable.Ro ws.Add(rownew) Next
AllDataTable.De faultView.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 datagrid. When I
sort the datagrid the selected item changes. I can not
find the event that is fired when the sorting occurrs
therfore I cannot...
|
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 from select statement of sql
query) in memory?
Thanks
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
|
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 no
option to sort the different columns during the call to the component.
|
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 provided by
clicking on a column header. By "Active Sort", I mean that editing a
value in a sorted column may cause the record to be moved to maintain...
|
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 System.Data.Index.Sort(Int32 left, Int32 right)
at System.Data.Index.InitRecords()
at System.Data.Index..ctor(DataTable table, Int32 indexDesc,...
| |
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 DataTable that is loaded during application
startup. I can sort with all the columns and everything works fine. I have
a method that can be invoked...
|
by: Bimal Kothari |
last post by:
private DataTable SortDataTable(DataTable GetDataTable, string sort)
{
DataTable _NewDataTable = GetDataTable.Clone();
int rowCount = GetDataTable.Rows.Count;
DataRow foundRows = GetDataTable.Select(null, sort);
// Sort with Column name
for (int i = 0; i < rowCount; i++)
{
object arr = new object;
|
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 population.
Whenever I call the thread, I pass it a structure containing the table and a
few other parameters. The table goes in as a reference,...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |