Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows combobox form
When I run the program, the combo box only shows:
"System.Data.DataRowView"
 

 
private void GetSupplierName()
        {
            string query = "Select * from Supplier";
            SqlCommand cmd = new SqlCommand(query, cn);
            cmd.CommandText = query;
            //cn.Open();

            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            cbosupplier.Items.Clear();
            cbosupplier.DisplayMember = "SupplierName";
            cbosupplier.ValueMember = "SupplierNo";
            cbosupplier.DataSource = ds.Tables[0];  
        }
 

Posted 23-Jun-12 21:24pm
wolfsor564
Edited 23-Jun-12 22:51pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

private void GetSupplierName()
 
        {
         try
            {
                cbosupplier.Items.Clear();
 
                string query = "Select distinct SupplierName from Supplier" +
                    " order by SupplierName asc";
                SqlCommand cmd = new SqlCommand(query, cn);
                cmd.CommandText = query;
                
 
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    cbosupplier.Items.Add(dr["SupplierName"].ToString());
                }
            }
            catch
            {
                MessageBox.Show("Error in Connection");
            }
           }
 

 

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Using DisplayMemberPath wasn't working but rather ItemTemplate. Here is an example.
 
<Window.Resources>
  <DataTemplate x:Key="comboTemplate">
        <TextBlock Text="{Binding Path=username}" />
  </DataTemplate>
</Window.Resources>
<ComboBox Margin="18,121,24,0" Name="cmbEmail" Tag="email" TabIndex="1" ToolTip="enter the email you signed up with here" IsEditable="True" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource comboTemplate}"  ItemsSource="{Binding}" Height="23" VerticalAlignment="Top" Style="{DynamicResource cmbBoxerrors}">
            <ComboBox.Text>
                <Binding Path="username"/>
            </ComboBox.Text>
 </ComboBox>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 334
2 CPallini 275
3 DamithSL 230
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100