How do I get around this DataGrid silliness?

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 21
Reputation: axfv is an unknown quantity at this point 
Solved Threads: 3
axfv axfv is offline Offline
Newbie Poster

How do I get around this DataGrid silliness?

 
0
  #1
Mar 16th, 2009
I have a DataGrid bound to a DataTable. For various reasons, I don't want to allow users to sort the data, but I want to sort the data once by "Username" as well as resize the columns.

I use DataTable.DefaultView.Sort = "Username" before binding it to DataGrid.

If I then create a DataGridTableStyle to set column widths for my DataGrid and add it to DataGrid, it overwrites the DataGrid's AllowSorting setting.

If I then set DataGridTableStyle.AllowSorting = False, it reverts back my sorting on DataTable for some reason. This behavior is undocumented and not mentioned anywhere on the web. The AllowSorting from DataGrid doesn't behave this way, so why the silliness? How do I get around it?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 29
Reputation: jbrock31 is an unknown quantity at this point 
Solved Threads: 1
jbrock31 jbrock31 is offline Offline
Light Poster

Re: How do I get around this DataGrid silliness?

 
0
  #2
Mar 16th, 2009
sorry wrong thread.
Last edited by jbrock31; Mar 16th, 2009 at 5:39 pm. Reason: deleting
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 66
Reputation: c0deFr3aK is an unknown quantity at this point 
Solved Threads: 10
c0deFr3aK's Avatar
c0deFr3aK c0deFr3aK is offline Offline
Junior Poster in Training

Re: How do I get around this DataGrid silliness?

 
0
  #3
Mar 19th, 2009
Originally Posted by axfv View Post
I have a DataGrid bound to a DataTable. For various reasons, I don't want to allow users to sort the data, but I want to sort the data once by "Username" as well as resize the columns.

I use DataTable.DefaultView.Sort = "Username" before binding it to DataGrid.

If I then create a DataGridTableStyle to set column widths for my DataGrid and add it to DataGrid, it overwrites the DataGrid's AllowSorting setting.

If I then set DataGridTableStyle.AllowSorting = False, it reverts back my sorting on DataTable for some reason. This behavior is undocumented and not mentioned anywhere on the web. The AllowSorting from DataGrid doesn't behave this way, so why the silliness? How do I get around it?
Try this one if it works:
Reset your datagrid into its original settings then make the sorting on your Query like :
  1. "SELECT username, password FROM your datatable ORDER BY username asc"
Bind it on your datagrid using your TableStyle
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: G-bot is an unknown quantity at this point 
Solved Threads: 0
G-bot G-bot is offline Offline
Newbie Poster

Re: How do I get around this DataGrid silliness?

 
0
  #4
Mar 20th, 2009
In the column properties of youf grid set sortmode = notsortable. This will disable sorting when the user clicks on the column header
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum


Views: 553 | Replies: 3
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC