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.
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.
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();
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.
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.
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?
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?