Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > problem with dataview sort
 

problem with dataview sort

I cannot get a dataview to sort at all based on the column name!

Here is the following code that I'm using:

lstReturnContact.DataSource = dsRolodexXSD.CONTACTS.Select(dsRolodexXSD.CONTACTS.Columns(1).ToString & " <> ''")
                    lstReturnContact.ValueMember = dsRolodexXSD.CONTACTS.Columns(0).ToString
                    lstReturnContact.DisplayMember = dsRolodexXSD.CONTACTS.Columns(1).ToString
                    dvFrAddr.Table = dsRolodexXSD.CONTACTS
                    dvFrAddr.Sort = dsRolodexXSD.CONTACTS.Columns(1).ToString


The dsRolodexXSD.CONTACTS.Columns(1).ToString contains the value "CONTACTNAME". I even try putting the string in manually (just "CONTACTNAME"), but it still doesn't work. I'm not getting an error. The listbox comes up fine with the data, but it is not sorted at all. If the sort method couldn't find the columnname, I would get an error.

Why is this not sorting???
MigrationUser 1  Monday, May 24, 2004 2:00 PM
You've set the DataSource to the returned array of DataRows from the Select() method, and <em>not</em> the DataView you prepared. Align your list control with the DataView instead.
MigrationUser 1  Monday, May 24, 2004 10:08 PM
I am currently having this same problem. When I set the sort property of the dataview it doesn't sort or generate any errors. The column I am trying to Sort by is of type integer.

dvData.Sort = "Age"

I don't know what the problem is. I check the msdn documentation of the DataView's Sort property and that is exactly how it says to do it.
MigrationUser 1  Sunday, July 25, 2004 4:29 PM
<hr>quote <strong>crpietschmann</strong>
I don't know what the problem is.<hr>
Make sure the DataGrid's DataSource <i>is</i> the DataView and not the table or array that contains the actual data.
MigrationUser 1  Sunday, July 25, 2004 10:28 PM
I found the answer to this problem at this link:
http://www.dotnet247.com/247reference/msgs/11/59230.aspx

I posted a quote from that page below:
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
Yes, your code snippet worked just fine. Here's the problem that I had.
Syntax, syntax, syntax. The following 2 blocks of code do NOT generate the
same result!

Dim y As Integer
for y = 0 To dvGlobalDataView.Count - 1
Console.WriteLine(dvGlobalDataView(y)("Description"))
Next

Dim z As Integer
For z = 0 To dvGlobalDataView.Table.Rows.Count - 1
Console.WriteLine(dvGlobalDataView.Table.Rows(z)("Description"))
Next

The former sorts and filters as per the .sort and .rowfilter properties and
the latter reveals the full table without sort or filter. Today's lesson,
RTFM, carefully!
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
MigrationUser 1  Sunday, July 25, 2004 11:23 PM

You can use google to search for other answers

Custom Search

More Threads

• Tranfer Data from Datagrid to DataTable
• DataGridView slect full row problem in virtual mode
• DataError event doesn't fire
• Two set of items binded to combo column of datagridview.
• Bindingsource
• DataGridView - set cursor on inserted row
• step bye step in filling a datagridview
• How to assign Different Datasource to DataGridViewComboboxColumn to Different Rows??
• Binding to array list
• dataGridView, Addnew failing, no error