组合框中的System.Data.DataRowView [英] System.Data.DataRowView in Combobox

查看:65
本文介绍了组合框中的System.Data.DataRowView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行程序时,组合框仅显示:
"System.Data.DataRowView"


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];  
        }

推荐答案

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");
            }
           }


使用DisplayMemberPath无效,而使用ItemTemplate.这是一个例子.

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>


作为替代,MSDN分辨率可从 ^ ]
As an alternative, MSDN resolution is available at http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/38f6c648-2a3a-4f07-8752-f3a42d071599[^]


这篇关于组合框中的System.Data.DataRowView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆