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 950055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:30:14+00:00 2026-05-15T23:30:14+00:00

I would like to perform an Except operation on set of items. Code is

  • 0

I would like to perform an Except operation on set of items.

Code is like this:

IEnumerable<DataGridViewColumn> dgvColumns = dataGridView.Columns.OfType<DataGridViewColumn>();
IEnumerable<DataColumn> dsColumns = dataSet.Tables[0].Columns.OfType<DataColumn>();

Now, how to select Columns from dataSet.Tables[0] which are not in dgvColumns?
I know that Columns from DataGridView are different type than Columns in DataSet. I want to pick up only a subset of common values. Like this:

        var ColumnsInDGV = from c1 in dgvColumns
                           join c2 in dsColumns on c1.DataPropertyName equals c2.ColumnName
                           select new { c1.HeaderText, c1.DataPropertyName, c2.DataType, c1.Visible };

Above code selects me “columns” that are in both sets. So I tought I will create another set of “columns” that are in DataSet:

  var ColumnsInDS = from c2 in dsColumns select new { HeaderText = c2.ColumnName, DataPropertyName = c2.ColumnName, c2.DataType, Visible = false };

and now that I will be able to perfrom Except like this:

var ColumnsOnlyInDS = ColumnsInDS.Except<ColumnsInDGV>;

But I am getting two errors:

  1. The type or namespace name ‘ColumnsInDGV’ could not be found (are you missing a using directive or an assembly reference?)
  2. Cannot assign method group to an implicitly-typed local variable

So the solution would be to build a class and then use it instead of implictly – typed local variable. But I think that developing a class only for this reason is a not necessery overhead.

Is there any other solution for this problem?

  • 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-15T23:30:14+00:00Added an answer on May 15, 2026 at 11:30 pm

    You’ve almost got it. You just need to write:

    // use () to pass a parameter
    // type (should) be inferred
    var ColumnsOnlyInDS = ColumnsInDS.Except(ColumnsInDGV);
    

    instead of:

    // do not use <> - that passes a type parameter;
    // ColumnsInDGV is not a type
    var ColumnsOnlyInDS = ColumnsInDS.Except<ColumnsInDGV>;
    

    Update: So, the above actually doesn’t work because Except depends on comparing items in two sequences for equality; obviously, your anonymous type has not overriden object.Equals and so each object that you create of this type is treated as a distinct value. Try this* instead:

    var dgvColumns = dataGridView.Columns.Cast<DataGridViewColumn>();
    var dsColumns = dataSet.Tables[0].Columns;
    
    // This will give you an IEnumerable<DataColumn>
    var dsDgvColumns = dgvColumns
        .Where(c => dsColumns.Contains(c.DataPropertyName))
        .Select(c => dsColumns[c.DataPropertyName]);
    
    // Then you can do this
    var columnsOnlyInDs = dsColumns.Cast<DataColumn>().Except(dsDgvColumn);
    

    *Note: Where in the above expression for dsDgvColumns makes more sense than SkipWhile because it will apply the specified filter over all results. SkipWhile would only apply the filter as long as it was true and would then stop applying it. In other words it would work if your DataGridViewColumn not bound to your DataSet were at the beginning of the DataGridView; but not if it were in the middle or at the end.

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

Sidebar

Related Questions

I would like to perform something similar to this (ie get the sum of
In my plugin code I would like to perform a WP_Query (or similar) which
I would like to perform a delete on my ObjectContext . This is my
I would like to perform checking on the following: VALID LINES; /**/ some code
I would like to perform a certain operation every time a user adds a
I would like to perform an operation on two generics argument of the same
I would like to perform the operation of convolution of sinus signal and rectangular
I would like to perform an ActiveRecord query that returns all records except those
I would like to perform a key event detection in textbox. The keys should
I would like to perform a bitwise exclusive or of two strings in python,

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.