DataRowView Sorting?

  • Thread starter Thread starter Able
  • Start date Start date
A

Able

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
 
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
 
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
 
This doesnt help because it only sorts one column in a two deminsional
array.

Regards Able
 
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
 
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.
 
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
 
Back
Top