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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:39:15+00:00 2026-06-02T22:39:15+00:00

I need help plz, I am just trying to bind a simple combo box

  • 0

I need help plz, I am just trying to bind a simple combo box to a table from the sql database which contains this data:

EmployeesTbl:
-------------
EmpID    EmpName   JobID   HireDate     Deleted 
1        Tom       1       12/4/2005    false
2        steve     1       5/5/2005     false
3        Maria     2       2/8/2010     false
<Window x:Class="TestGlassButton.Window4"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window4" Height="300" Width="300">
       <Grid>
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="54,213,0,0" 
                  Name="cmbCapsNme" VerticalAlignment="Top" Width="132" 
                  ItemsSource="{Binding}"
                  DisplayMemberPath="EmpArbName"
                  SelectedValuePath="EmpID"/>
       </Grid>
 </Window>
namespace TestGlassButton
{

public partial class Window4 : Window
{
    public DataSet SelAllCaps()
    {
        SqlConnection SqlCon = new SqlConnection("Data Source=.;Initial Catalog=Rest;User ID=m*201m;Password=12345");
        // captains names & ID   
        SqlCommand SqlCmdAllCaps = new SqlCommand();
        SqlCmdAllCaps.Connection = SqlCon;
        SqlCmdAllCaps.CommandType = CommandType.Text;
        SqlCmdAllCaps.CommandText = "select EmpID ,EmpArbName from dbo.EmployeesTbl where JobID = 3 order by EmpArbName";
        SqlCon.Open();
        SqlDataAdapter dapAllCaps = new SqlDataAdapter();
        dapAllCaps.SelectCommand = SqlCmdAllCaps;
        DataSet dsAllEmpsInfo = new DataSet();
        dapAllCaps.Fill(dsAllEmpsInfo, "EmployeesTbl");
        SqlCon.Close();
        return dsAllEmpsInfo;
    }

    private void BindCaps()
    {

        DataSet ds = SelAllCaps();
        List<CapsClass> capList = new List<CapsClass>();
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            capList.Add(new CapsClass(Convert.ToInt32(ds.Tables[0].Rows[i]["EmpID"]),
                ds.Tables[0].Rows[i]["EmpArbName"].ToString()));
        }
        ds = null;
        cmbCapsNme.ItemsSource = capList;
        cmbCapsNme.DisplayMemberPath = "EmpArbName";
        cmbCapsNme.SelectedValuePath = "EmpID";
        cmbCapsNme.SelectedIndex = -1;
    }

    public Window4()
    {
        InitializeComponent();
        BindCaps();
     }
}
class CapsClass
{
    Int32 _capID=-1;
    string _capNme;

    public CapsClass(Int32 CapID, String CapNme)
    {
        this._capID = CapID;
        this._capNme = CapNme;
    }

    public Int32 CapID
    {
        get { return _capID; }
        set { _capID = value; }
    }

    public string CapNme
    {
        get { return _capNme; }
        set { _capNme = value; }
    }
}
}

but when I execute my project, data does’t appear in my combo box, it shows only no. of rows.
Is there any wrong & my code, Any ideas please?

  • 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-02T22:39:22+00:00Added an answer on June 2, 2026 at 10:39 pm

    Your combobox has DisplayMemberPath=”EmpArbName” and SelectedValuePath=”EmpID” but your CapClass has no property with this names.

    I will try to change that property to CapID and CapNme, or bind directly to the datatable.

    cmbCapsNme.ItemsSource = ds.Tables[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to populate the combo box Items from a database query (this part
need help/guide for sql select query, I have 2 table stock and stock_history, in
need help in error in database pivot. i have table tamed table_score like below:
I have a sql script to create a new database which i need to
Need help to convert code from asp control to input type to fetch file
Need help with deleting call log from multi numbers, using the following code i
Need help writing a script downloads data from google insight using c# this is
need help regarding USSD Gateway. I have to develop an app, which will directly
I need help with a function so that I can upload a picture from
Possible Duplicate: need help with some stored procedure plz ERROR:- A SELECT statement that

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.