PC Review


Reply
Thread Tools Rate Thread

Sorting DataGrid via SqlCeResultSet verses DataTable?

 
 
Jen
Guest
Posts: n/a
 
      3rd Oct 2005
I have used the code below in the past to sort a data grid column. Now I'm
using a SqlCeResultSet as my DataSource for the grid.



Since the SqlCeResultSet is new to me I was hoping someone could point out
what needs to be converted to support using a resultset instead of a
DataTable.



Thanks!



// Sort grid by column
void SortGrid(int col)
{


if (this.DataSource is DataTable)
this.DataSource = (this.DataSource as
DataTable).DefaultView;


DataView vw = (DataView)this.DataSource;
string sort = vw.Table.Columns[col].ColumnName;

if (vw.Sort.StartsWith(sort))
{
if (vw.Sort.EndsWith("ASC"))
vw.Sort = sort + " DESC";
else
vw.Sort = sort + " ASC";
}

else
{
vw.Sort = sort + " ASC";
}
}


 
Reply With Quote
 
 
 
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      3rd Oct 2005
You can not sort/filter RS. You have to get new sorted/filtered RS using
respective SQL query and bind it to the grid.

Don't forget to dispose of an old RS.


Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/...ramework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

"Jen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have used the code below in the past to sort a data grid column. Now I'm
>using a SqlCeResultSet as my DataSource for the grid.
>
>
>
> Since the SqlCeResultSet is new to me I was hoping someone could point out
> what needs to be converted to support using a resultset instead of a
> DataTable.
>
>
>
> Thanks!
>
>
>
> // Sort grid by column
> void SortGrid(int col)
> {
>
>
> if (this.DataSource is DataTable)
> this.DataSource = (this.DataSource as
> DataTable).DefaultView;
>
>
> DataView vw = (DataView)this.DataSource;
> string sort = vw.Table.Columns[col].ColumnName;
>
> if (vw.Sort.StartsWith(sort))
> {
> if (vw.Sort.EndsWith("ASC"))
> vw.Sort = sort + " DESC";
> else
> vw.Sort = sort + " ASC";
> }
>
> else
> {
> vw.Sort = sort + " ASC";
> }
> }
>



 
Reply With Quote
 
Jen
Guest
Posts: n/a
 
      3rd Oct 2005
Thanks

You saved me alot of time

"Ilya Tumanov [MS]" <(E-Mail Removed)> wrote in message
news:43419f91$(E-Mail Removed)...
> You can not sort/filter RS. You have to get new sorted/filtered RS using
> respective SQL query and bind it to the grid.
>
> Don't forget to dispose of an old RS.
>
>
> Best regards,
>
> Ilya
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> *** Want to find answers instantly? Here's how... ***
>
> 1. Go to
> http://groups-beta.google.com/group/...ramework?hl=en
> 2. Type your question in the text box near "Search this group" button.
> 3. Hit "Search this group" button.
> 4. Read answer(s).
>
> "Jen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have used the code below in the past to sort a data grid column. Now I'm
>>using a SqlCeResultSet as my DataSource for the grid.
>>
>>
>>
>> Since the SqlCeResultSet is new to me I was hoping someone could point
>> out what needs to be converted to support using a resultset instead of a
>> DataTable.
>>
>>
>>
>> Thanks!
>>
>>
>>
>> // Sort grid by column
>> void SortGrid(int col)
>> {
>>
>>
>> if (this.DataSource is DataTable)
>> this.DataSource = (this.DataSource as
>> DataTable).DefaultView;
>>
>>
>> DataView vw = (DataView)this.DataSource;
>> string sort = vw.Table.Columns[col].ColumnName;
>>
>> if (vw.Sort.StartsWith(sort))
>> {
>> if (vw.Sort.EndsWith("ASC"))
>> vw.Sort = sort + " DESC";
>> else
>> vw.Sort = sort + " ASC";
>> }
>>
>> else
>> {
>> vw.Sort = sort + " ASC";
>> }
>> }
>>

>
>



 
Reply With Quote
 
Darren Shaffer
Guest
Posts: n/a
 
      3rd Oct 2005
Jen,

The ResultSetView, unlike the DataView, does not expose a Sort member, but
does implement the IBindingList interface and exposes an ApplySort method

which you could implement. Sorry I don't have a sample of that handy, but

there are examples of implementing ApplySort on the web.

--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com


"Jen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have used the code below in the past to sort a data grid column. Now I'm
>using a SqlCeResultSet as my DataSource for the grid.
>
>
>
> Since the SqlCeResultSet is new to me I was hoping someone could point out
> what needs to be converted to support using a resultset instead of a
> DataTable.
>
>
>
> Thanks!
>
>
>
> // Sort grid by column
> void SortGrid(int col)
> {
>
>
> if (this.DataSource is DataTable)
> this.DataSource = (this.DataSource as
> DataTable).DefaultView;
>
>
> DataView vw = (DataView)this.DataSource;
> string sort = vw.Table.Columns[col].ColumnName;
>
> if (vw.Sort.StartsWith(sort))
> {
> if (vw.Sort.EndsWith("ASC"))
> vw.Sort = sort + " DESC";
> else
> vw.Sort = sort + " ASC";
> }
>
> else
> {
> vw.Sort = sort + " ASC";
> }
> }
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid with SqlCeResultSet vijay Microsoft Dot NET Compact Framework 0 8th Aug 2007 03:27 AM
datagrid dataset dataview datatable sorting Nathan Franklin Microsoft VB .NET 0 19th Jan 2006 06:15 AM
Sorting datagrid-dataview-datatable =?Utf-8?B?c3ViVA==?= Microsoft ADO .NET 2 27th May 2004 04:56 PM
DataGrid Sorting returns wrong values from dataTable vijai thoppae Microsoft Dot NET Framework Forms 2 12th May 2004 10:14 PM
Datagrid (Winform) / Datatable / Sorting problem Daniel Microsoft ADO .NET 0 30th Nov 2003 06:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 PM.