Advertisement

03.17.2008 at 09:00AM PDT, ID: 23247440 | Points: 125
[x]
Attachment Details
DataGridView not sorting header with LINQ as datarouce
Tags: C#
Hi,

I have been working on ASP.NET for a while but now I'm in the process of writing a Windows Form Application. I am using VS 2008. I have created the entity model from my SQL 2005 database. I am writing a simple search form with text boses for first name, last name and a Datagridview which when the Search button is pressed, loads the data into the grid. This is working perfectly fine. However, when i click the column headers, the columns do not sort like the GridView Web Control. Is it required to write a custom Sorting Binding list for the DataGridView control?
The data source is being attached as follows,
var pts=from p  in patients
             select p;
grdPatients.DataSource=pts;
Also,  if there is such a difference between the controls, i would like to design my application in such a way that later when I am ready to write a web application, I can just switch the presentation layer and would not have to touch the business logic. I would like some general feedback on how to do this.
Thanks in advance.
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: jainpriyanka
Question Asked On: 03.17.2008
Participating Experts: 2
Points: 125
Views: 0
Translate:
Loading Advertisement...
03.18.2008 at 06:29AM PDT, ID: 21150708

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.18.2008 at 10:11AM PDT, ID: 21153336

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.18.2008 at 10:19AM PDT, ID: 21153446

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2008 at 08:33AM PDT, ID: 21180608

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2008 at 08:37AM PDT, ID: 21180642

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2008 at 08:53AM PDT, ID: 21180771

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2008 at 07:23PM PDT, ID: 21184502

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.24.2008 at 06:46AM PDT, ID: 21193467

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.24.2008 at 09:25AM PDT, ID: 21194601

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.18.2008 at 06:29AM PDT, ID: 21150708

Rank: Wizard

What is the 'SortMode' for the columns?  What type of data is in the column?  The DataGridView should handle the sorting internally.

Bob
 
03.18.2008 at 10:11AM PDT, ID: 21153336
The default sort mode set for the columns is automatic. The data type of the columns range from string to int to date fields. None of them seem to sort. Its a simple WinForm in VS 2008 with a Datagridview..In the button_click event, i have added this code,
var pts=from p  in patients
             select p;
grdPatients.DataSource=pts;
Thats it...but the sorting doesnt work.
 
03.18.2008 at 10:19AM PDT, ID: 21153446

Rank: Wizard

What is SortOrder set to?  There is also the Sorted and SortCompare event that fires when a sort comparison needs to be performed.

Bob

 
03.21.2008 at 08:33AM PDT, ID: 21180608
For what you are doing, I would basically throw in a Bindingsource, and set the DataSource of your view to the binding source...  then set the datasource of your binding source to
bindingSource.DataSource = Context.Patients.GetNewBindingList();
 
03.21.2008 at 08:37AM PDT, ID: 21180642
Praesidium,
 Could you explain that in a little more detail? With some code?
Thanks!
 
03.21.2008 at 08:53AM PDT, ID: 21180771
Sure, open your form...  From the tools, drag a BindingSource onto your form.  Then in the properties set the Datasource of your DataGridView to your binding source (it should be on the list now).  Now, flip to code view, go to your constructor.  Your bindingsource is probably named bindingSource1 so add the line of code that says:
bindingSource1.DataSource = Context.Patients.GetNewBindingList();
Of course, you will have to change Context to the actual name (path) to your DataContext (not sure if you are using a provider model, etc.)...

Then try your sorting, you should find yourself able to sort, etc., just fine.
 
03.21.2008 at 07:23PM PDT, ID: 21184502
When i do the above, it gives me a compile error of Error            'System.Data.Objects.ObjectQuery<WritepadModel.Patients>' does not contain a definition for 'GetNewBindingList' and no extension method 'GetNewBindingList' accepting a first argument of type 'System.Data.Objects.ObjectQuery<WritepadModel.Patients>' could be found (are you missing a using directive or an assembly reference?)      
So I changed the GetNewBindingList to ToList since i am using an Entity model to query against.but it still doesnt sort automatically.
 
03.24.2008 at 06:46AM PDT, ID: 21193467
You have System.Data.Linq and System.Core referenced?  Are you using the entity model created by aLInqToSql class, or by SqlMetal or SqlTac?  How did you create the entity model, by hand?
 
03.24.2008 at 09:25AM PDT, ID: 21194601
I do have the System.Data.Linq and System.Core referenced. The entity model i created was by selecting Add Item and then adding the ADO.NET entity model and then pointing to the database. So I assume this is SQLmetal. Is that right?
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628