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

  • Home
  • SEARCH
  • 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 8678079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:37:15+00:00 2026-06-12T20:37:15+00:00

i am binding the below data to a drop down but am not able

  • 0

i am binding the below data to a drop down but am not able to get disctinct value. Please help. Find the code snippet below

var SalesOrgTypes = (from s in tblSales
                         orderby s.SalesOrg ascending
                         select new DropDownItem
                         {
                             Value = s.SalesOrg,
                             Text = s.SalesOrg + " - " + s.SalesOrgDesc
                         }).Distinct();
  • 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-06-12T20:37:16+00:00Added an answer on June 12, 2026 at 8:37 pm

    Distinct() is using the definied Equals(object obj) method of the DropDownItem. You have to define a proper IEqualityComparer and give it to the Distinct(IEqualityComparer<T>) method to tell Distinct not to use the native Equals(object obj) method, but your own equalization.

    class DropDownItemEqualityComparer : IEqualityComparer<DropDownItem>
    {
        #region IEqualityComparer<DropDownItem> Member
    
        public bool Equals(DropDownItem x, DropDownItem y)
        {
            return
                x == null || y == null 
                ? false
                : x.Value == y.Value && x.Text == y.Text; 
            //Or whatever properties you want to be equal
        }
    
        public int GetHashCode(DropDownItem obj)
        {
            if (obj != null)
                return
                    obj.Value.GetHashCode() + obj.Text.GetHashCode();
            else
                throw new ArgumentNullException("obj");
        }
    
        #endregion
    }
    

    Then you can give this to the Distinct method

    var SalesOrgTypes = (from s in tblSales
                             orderby s.SalesOrg ascending
                             select new DropDownItem
                             {
                                 Value = s.SalesOrg,
                                 Text = s.SalesOrg + " - " + s.SalesOrgDesc
                             }).Distinct(new DropDownItemEqualityComparer());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble binding the selected value of a drop down list to the
What is the best solution for not being able to use data binding on
Below is a sample implementation that uses metro API and data binding (using MVVM)
I have a code snippet as below <CheckBox Name=cb Margin=1,2,1,0 IsChecked={Binding Path=IsManager} IsEnabled=True/> Consider
I have the following Data template with triggers: <DataTemplate.Triggers> <DataTrigger Binding={Binding IsCalled} Value=Yes> <Setter
My application is showing this error below: Data binding directly to a store query
How do I get Grails data binding to correctly bind referenced objects (such as
I have a style template (below) that does not update when my Tag binding
I want to select Algeria as default selected value in drop down list.I am
I'm trying to get to grips with the different ways of styling/binding data in

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.