zoukankan      html  css  js  c++  java
  • WPF 中ComboBox绑定DataSet

    唉,其实逻辑比较简单,但是因为一个小小的问题搞了1个小时

    方法1,前台xaml方式绑定

     <ComboBox Name="cbTypeIn" ItemSource={Binding}   IsReadOnly="True">
                   
    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding ID}" Width="20" />
                            <TextBlock Text="{Binding typeName}" Width="70" />
                        </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>

      </ComboBox>

    使用了数据模板来显示类型ID和类型名称。当然一般情况下类型ID是隐藏不显示,这个无所谓了

    后台要指定数据源

    this.this.cbTypeIn.DataContext = ds.Tables[0].DefaultView;

    方法2完全c#后台代码

    前台

     <ComboBox Name="cbTypeIn"  IsReadOnly="True">   </ComboBox>

    后台

       this.cbTypeIn.ItemsSource = ds.Tables[0].DefaultView;
                this.cbTypeIn.DisplayMemberPath = "typeName";
                this.cbTypeIn.SelectedValuePath = "ID";

    我因为一个s问题耽误了1个小时

    原来wpf中的数据源字段区分大小写

    本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

  • 相关阅读:
    gcc代码反汇编查看内存分布[1]: gcc
    centos5.5 安装git
    裸机代码(uboot) : clear bss
    互联网协议入门
    git从github下载代码
    linux账户管理(centos)
    jz2440: linux/arch/arm/下面的plat-和mach-
    位置无关码
    【漫画】什么是外部排序?【转】
    快速排序 Vs. 归并排序 Vs. 堆排序——谁才是最强的排序算法
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319324.html
Copyright © 2011-2022 走看看