Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6123305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:00:00+00:00 2026-05-23T16:00:00+00:00

I’m working on a form that has a few data grid views that are

  • 0

I’m working on a form that has a few data grid views that are populated from LINQ queries, no problem there it works as it should however that sorting does not work. After doing some reading its because LINQ results do not support sorting.

As I have the LINQ results already is there a way of copying the results into a dataset or datatable then binding the data grid view to that so sorting will work?

Thanks

EDIT:
Thanks to everyone for the answers, sadly I’m off on holiday for 2 weeks so cant try out and upvote the correct one. However when I return it will be on the top of my list

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:00:00+00:00Added an answer on May 23, 2026 at 4:00 pm

    In the end I used bits from each option and a little tweak to get it to work with nullable fields.

    First thing is getting the CopyToDataTable function into VB, this is done here

    http://msdn.microsoft.com/en-us/library/bb669096.aspx

    When I tried this it would fail if the column was nullable so I searched and found a mod to that code that would work. Here it is in full

    Public Function ExtendTable(ByVal table As DataTable, ByVal type As Type) As DataTable
         For Each f As FieldInfo In type.GetFields()
           If (Not _ordinalMap.ContainsKey(f.Name)) Then
             Dim dc As DataColumn
             dc = If(table.Columns.Contains(f.Name), table.Columns(f.Name), table.Columns.Add(f.Name, f.FieldType))
             _ordinalMap.Add(f.Name, dc.Ordinal)
           End If
         Next f
         For Each p As PropertyInfo In type.GetProperties()
           If Not _ordinalMap.ContainsKey(p.Name) Then
             Dim colType As Type = p.PropertyType
             If (colType.IsGenericType) AndAlso (colType.GetGenericTypeDefinition() Is GetType(Nullable(Of ))) Then
               colType = colType.GetGenericArguments()(0)
             End If
             Dim dc As DataColumn = IIf(table.Columns.Contains(p.Name), table.Columns(p.Name), table.Columns.Add(p.Name, colType))
             _ordinalMap.Add(p.Name, dc.Ordinal)
           End If
         Next
         Return table
        End Function
    

    Upvotes all round as they all would have worked I just took this option as it is neater

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Rails app that sends data through a form. I want
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
i am working on a web form that has repeating ui elements using the
I am working on a basic app that has a public facing form (for
I'm working on a form that will display links to open different types of
I'm working on a star schema for analysis of posted form data. The site
I'm currently working on a reasonably complicated data input form, based around ASP.NET Web
I'm building a form in access that has a several sub-forms in a tab
I am working on a small project that is receiving XML data in string
I am working on a search application that uses a form with 16 filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.