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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:14:55+00:00 2026-05-25T02:14:55+00:00

I want to retrieve data from 2 columns of my database table and bind

  • 0

I want to retrieve data from 2 columns of my database table and bind those 2 columns to the combobox item index and item value properties respectively. I retrieve my data from the samples table of my database with this anonymous query:

var result = from obj in context.Samples
             select new { obj.ID , obj.Name };

I want to set the default index value of each item in my combobox to obj.ID and the value of each respective combobox item to obj.Name so that rather than the items in my combo box having default values starting from 0, 1, 2…. their index values will have the value of obj.ID returned by my LINQ query and the actual value of the item will be obj.Name.

Sorry if this is a silly/amateurish question but I’ve spent a few hours trying to fix it and had no luck. Thanks in advance.

  • 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-25T02:14:56+00:00Added an answer on May 25, 2026 at 2:14 am

    The SelectedIndex property always goes from -1 (no item is selected) to count-1, you can’t change that. If you want to store the ID and Name for each item in the ComboBox, you can do that:

    Create non-anonymous type Sample that contains those two properties. Then assign (or bind) collection of Samples to the ComboBox‘s ItemSource and set DisplayMemberPath toName. Then you can access the ID of the selected item using ((Sample)yourComboBox.SelectedItem).ID.

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

Sidebar

Related Questions

I want to retrieve the java data types of the columns of a table
I use the next code to retrieve data from a table in the database:
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
I want to generate some formatted output of data retrieved from an MS-Access database
I want to retrieve a set of records from a database, do a rs.next()
I want to retrieve all records from one table when there are no matches
I want to get data from the database (MySQL) by JPA, I want it
I am retriving data from database.TableName:Contacts. There are two fields of this table.First_Name and
What I want to do is retrieve all emails from MS SQL Customer table
I want to retrieve data from Oracle Data Base which has SID, Port, Host

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.