943,696 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 851
  • VB.NET RSS
Mar 16th, 2009
0

How do I get around this DataGrid silliness?

Expand 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?
Reputation Points: 10
Solved Threads: 3
Newbie Poster
axfv is offline Offline
22 posts
since Nov 2008
Mar 16th, 2009
0

Re: How do I get around this DataGrid silliness?

sorry wrong thread.
Last edited by jbrock31; Mar 16th, 2009 at 5:39 pm. Reason: deleting
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008
Mar 19th, 2009
0

Re: How do I get around this DataGrid silliness?

Click to Expand / Collapse  Quote originally posted by axfv ...
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 :
VB.NET Syntax (Toggle Plain Text)
  1. "SELECT username, password FROM your datatable ORDER BY username asc"
Bind it on your datagrid using your TableStyle
Reputation Points: 11
Solved Threads: 10
Junior Poster in Training
c0deFr3aK is offline Offline
71 posts
since Mar 2009
Mar 20th, 2009
0

Re: How do I get around this DataGrid silliness?

In the column properties of youf grid set sortmode = notsortable. This will disable sorting when the user clicks on the column header
Reputation Points: 10
Solved Threads: 0
Newbie Poster
G-bot is offline Offline
4 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: need help to pass values to array in for loop
Next Thread in VB.NET Forum Timeline: Images





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC