PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Sorting DataGrid via SqlCeResultSet verses DataTable?
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Sorting DataGrid via SqlCeResultSet verses DataTable?
![]() |
Sorting DataGrid via SqlCeResultSet verses DataTable? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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"; } } |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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...framework?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" <jpierce2@austin.rr.com> wrote in message news:eE3PYsFyFHA.3236@TK2MSFTNGP14.phx.gbl... >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"; > } > } > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks
You saved me alot of time ![]() "Ilya Tumanov [MS]" <ilyatum@online.microsoft.com> wrote in message news:43419f91$1@news.microsoft.com... > 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...framework?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" <jpierce2@austin.rr.com> wrote in message > news:eE3PYsFyFHA.3236@TK2MSFTNGP14.phx.gbl... >>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"; >> } >> } >> > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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" <jpierce2@austin.rr.com> wrote in message news:eE3PYsFyFHA.3236@TK2MSFTNGP14.phx.gbl... >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"; > } > } > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


