473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DataRowView Sorting?

Dear friends

I am using FindRows methods of the DataView to select multiple rows as this:

Dim custView As DataView = New DataView(custDS.Tables("Customers"), "", _
"CompanyName, ContactName",
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = custView.FindRows(New object() {"The
Cracker Box"})

Dim myDRV as DataRowView
For Each myDRV In foundRows

ListBox1.Items.Add(myDRV("CompanyName").ToString() )
Next

But how do I sort the array (foundRows) before adding the items to the
listbox? The DataRowView has a sort method but I dont know how to use it.

Regards Able
Nov 20 '05 #1
7 5054
Hi Able,

Is it CompanyName that you want to sort by? If so, once you've
filled that ListBox, you could set it's Sorted property to True and have
<it> do the sorting.

ListBox1.BeginUpdate
For Each myDRV In foundRows
ListBox1.Items.Add(myDRV("CompanyName").ToString() )
Next

ListBox1.Sorted = True
ListBox1.EndUpdate

The Begin and End Updates will stop it displaying while you fill
and sort it.

Regards,
Fergus
Nov 20 '05 #2
Cor
Hi Able,

I did not use the dataview a while, but I think you are looking for this
Dim custView As DataView = New DataView(custDS.Tables("Customers"), "", _
"CompanyName, ContactName",
DataViewRowState.CurrentRows)
custView.Sort = "CompanyName ASC"
Dim foundRows() As DataRowView = custView.FindRows(New object() {"The
Cracker Box"})


But in addition to Fergus, the dataview is of course typical a control to
use to bind to another control (or let's say better, to use as a kind of
filter for binding a dataset or table to a control), and not to select rows
and then fill the control with it.
Cor
Nov 20 '05 #3
This doesnt help because it only sorts one column in a two deminsional
array.

Regards Able
"Fergus Cooney" <fi****@post.com> skrev i melding
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi Able,

Is it CompanyName that you want to sort by? If so, once you've
filled that ListBox, you could set it's Sorted property to True and have
<it> do the sorting.

ListBox1.BeginUpdate
For Each myDRV In foundRows
ListBox1.Items.Add(myDRV("CompanyName").ToString() )
Next

ListBox1.Sorted = True
ListBox1.EndUpdate

The Begin and End Updates will stop it displaying while you fill
and sort it.

Regards,
Fergus

Nov 20 '05 #4
My issue was to sort the searched rows. This doesnt.

Regards Able

"Cor" <no*@non.com> skrev i melding
news:ua**************@TK2MSFTNGP09.phx.gbl...
Hi Able,

I did not use the dataview a while, but I think you are looking for this
Dim custView As DataView = New DataView(custDS.Tables("Customers"), "", _ "CompanyName, ContactName",
DataViewRowState.CurrentRows)
custView.Sort = "CompanyName ASC"
Dim foundRows() As DataRowView = custView.FindRows(New object() {"The
Cracker Box"})


But in addition to Fergus, the dataview is of course typical a control to
use to bind to another control (or let's say better, to use as a kind of
filter for binding a dataset or table to a control), and not to select

rows and then fill the control with it.
Cor

Nov 20 '05 #5
HI Able,

You've responded to both our help with negativity!
My posts started with a question:

Is it CompanyName that you want to sort by?

This was an invitation to tell us what you want. The rest was to save you time
if it <was> just CompanyName. Now you've missed an opportunity to put us
on the right track.

My confusion lies in the fact that whatever dimension your array is, you are putting a
list of CompanyNames and <only> CompanyNames into the ListBox.

Another confusion is that you want to sort foundRows which is an array of
DataRowViews. A DataRowView cannot be sorted, although an array of them
can. But as Cor has shown you with a perfect example, you <can> sort the
<DataView>. Why extract them unsorted and then sort the array (with difficulty)
when you can get the DataView to extract them already sorted?

Another confusion is that you are providing a Sort specification when you
create the DataView. Is it not working?

Regards,
Fergus
Nov 20 '05 #6
I apologize but I am not skilled in this matter.

The search is filtered by the column "CompanyName" and returns a two
dimensional array in foundRows. My goal is to sort the array foundRows by
another column lets say "Products". I managed to sort it by loading the
search result in another two deminsional array and sorted the new array
using the shell-sort technic.

I appreciate you for helping

Regards Able.

"Fergus Cooney" <fi****@post.com> skrev i melding
news:u5**************@TK2MSFTNGP09.phx.gbl...
HI Able,

You've responded to both our help with negativity!
My posts started with a question:

Is it CompanyName that you want to sort by?

This was an invitation to tell us what you want. The rest was to save you time if it <was> just CompanyName. Now you've missed an opportunity to put us
on the right track.

My confusion lies in the fact that whatever dimension your array is, you are putting a list of CompanyNames and <only> CompanyNames into the ListBox.

Another confusion is that you want to sort foundRows which is an array of DataRowViews. A DataRowView cannot be sorted, although an array of them
can. But as Cor has shown you with a perfect example, you <can> sort the
<DataView>. Why extract them unsorted and then sort the array (with difficulty) when you can get the DataView to extract them already sorted?

Another confusion is that you are providing a Sort specification when you create the DataView. Is it not working?

Regards,
Fergus

Nov 20 '05 #7
Cor
Hi Able,
So

custView.Sort = "CompanyName, products ASC"

I did not look at the rest, but when is products your item
What is the shell sort technique I dont know that at the moment.

And although I hate SQL, I don't understand why your SQL clause is not just

Select * from x where company = 'x" ordered by company, products" or
something.
Gives you the less IO.

Cor

The search is filtered by the column "CompanyName" and returns a two
dimensional array in foundRows. My goal is to sort the array foundRows by
another column lets say "Products". I managed to sort it by loading the
search result in another two deminsional array and sorted the new array
using the shell-sort technic.


Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Hoge | last post by:
I have a datagrid that needs to display information from a related table, and I have use a template column to pass the Container.DataItem object to a method called ShowPub as follows: ...
1
by: VMI | last post by:
I have a field in my DataRowView that's read-only because it's a "join" of several other fields of the same DataRowView. For example, the field "Input" concatenates fields "Addr1", "City", "St",...
5
by: karim | last post by:
I am getting the error below when I try to use DataRowView in my aspx page. I am using the System.Data in my code behind. I even tried importing system.Data in the aspx. I have to qualify it with...
1
by: Guoqi Zheng | last post by:
Dear Sir, I need to access the datasource of a repeater control. I used CType(e.Item.DataItem, DataRowView), but obviously it does not work. Can some one tell me what I did wrong? See my...
2
by: Geoff Jones | last post by:
Hi Suppose I have a loop such as: For Each x As DataRowView In dataViewObj ' Some calculations go here Next Suppose we to access within the loop not only the current row but the next one...
2
by: Frank | last post by:
Hi, I want to put a datarowview aside to use later on. How? dim curRow as datarowview dim oldRow as datarowview oldrow=currow doesn't do the trick because I save the object ref and oldrow...
2
by: Joe | last post by:
Hello All: How have you used the DataRowView. I am familiar w/ DataRow (of course!), but haven't had the need to use the DataRowView. When would you use it? Thanks. Joe
0
by: rockdale | last post by:
private void dgrid_OnItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType ==ListItemType.Item||e.Item.ItemType ==ListItemType.AlternatingItem)...
3
by: needin4mation | last post by:
In this code: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView rowView =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.