刚开始学习数据绑定的东西,

private void Form1_Load(object sender, EventArgs e)
{
IList<TLayer> tt = new List<TLayer>();
tt.Add(new TLayer("Layer1", ""));
tt.Add(new TLayer("Layer2", ""));
tt.Add(new TLayer("Layer3", ""));
tt.Add(new TLayer("Layer4", ""));
tt.Add(new TLayer("Layer5", ""));
comboBox1.DataSource = tt;
comboBox1.DisplayMember = "NameN";
comboBox1.ValueMember = "FL";
} public class TLayer
{
public string NameN;public string FL;public TLayer(string NameN, string FL)
{
this.NameN = NameN;
this.FL = FL;
}
}

代码如上,显示是这个样子的

网上的示例   http://www.cnblogs.com/shuang121/archive/2012/11/21/2780819.html

仔细对比发现,唯一的区别是示例中是对公有字段进行了属性封装。而这就是问题关键,修改后如下,即可正常显示

public class TLayer
{
public string NameN { get; set; }
public string FL { get; set; } public TLayer(string NameN, string FL)
{
this.NameN = NameN;
this.FL = FL;
}
}

Winform Combox DataSource 之不显示 displayemember 内容的更多相关文章

  1. WinForm中遇到Label要显示的内容太长,自动换行

    很多朋友都会在开发WinForm中遇到Label要显示的内容太长,但却不能换行的问题.这里我总结了几种方法,供大家参考. 第一种是把Label的AutoSize属性设为False,手动修改Label的 ...

  2. winform里面网页显示指定内容

    今天有个同事问了一下我,怎么在winform里面打开网页啊?我们都是基于C/S的开发,很少接触winform,所以我当时就懵了,实在不知道怎么回答,所以索性说不知道.但是我又想了想,这个应该是个很简单 ...

  3. C# Winform ComBox三种赋值方式

    https://www.cnblogs.com/ingstyle/p/4815303.html 第一种方法: DataTable dt = new DataTable(); dt.Columns.Ad ...

  4. C#中winform中panel重叠无法显示问题

    C#中winform中panel重叠无法显示问题: 最近开发一个项目有个需求是需要多个模式来回切换的,本来考虑使用多个窗口来实现这个功能,但是这样做浪费资源,而且工作量大,所以想到使用panel控件来 ...

  5. CozyRSS开发记录15-获取和显示RSS内容

    CozyRSS开发记录15-获取和显示RSS内容 1.内容列表 我们先给RSSContentFrame增加一个ViewModel,里面和RSS源列表一样,提供一个ObservableCollectio ...

  6. 显示textarea内容的时候没有自动换行

    显示textarea内容的时候没有自动换行,网上找了好久,在一个论坛里找到解决方法: 1.把从数据库读出来的内容存放在一个Div内,例如: <div class="new-commen ...

  7. gridView RowDataBound事件 鼠标经过行颜色变化及根据字段值显示指定内容

    protected void gvBarInfo_RowDataBound(object sender, GridViewRowEventArgs e)        {            if ...

  8. EditTextPreference点击后输入框显示隐藏内容,类似密码输入(转)

    http://bbs.anzhuo.cn/thread-928131-1-1.html EditTextPreference点击后输入框显示隐藏内容,类似密码输入... [复制链接]     aski ...

  9. bootstrap模态框modal使用remote第二次加载显示相同内容解决办法

    bootstrap模态框modal使用remote动态加载内容,第二次加载显示相同内容解决办法 bootstrap的modal中,使用remote可以动态加载页面到modal-body中,并弹窗显示 ...

随机推荐

  1. button hot key 热键

    <Button x:Name="ScanIDButton" Margin="11,0,0,0" IsEnabled="{Binding Elem ...

  2. struct 类型重定义

    类型定义的那个头文件只需要在功能源文件里#include 开始在主函数源文件里也#include,所以出现了重定义

  3. Java利用Preferences设置个人偏好

    Java利用Preferences设置个人偏好 Preferences的中文意思即偏好或喜好的意思,也就是说同一个程序在每次运行完后,可以通过Preferences来记录用户的偏好,下次启动时,程序会 ...

  4. 图说设计模式(UML和设计模式)

    https://github.com/me115/design_patterns http://design-patterns.readthedocs.org/zh_CN/latest/index.h ...

  5. Spring官网改版后下载

    Spring官网改版后找了好久都没有找到直接下载Jar包的链接,下面汇总些网上提供的方法,亲测可用. 1.直接输入地址,改相应版本即可:http://repo.springsource.org/lib ...

  6. 【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】

    报错: HTTP Status 500 - Could not write content: No serializer found for class org.hibernate.proxy.poj ...

  7. Codeforces Round #355 (Div. 2)-A

    A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walkin ...

  8. Swift3.0语言教程获取字符串长度

    Swift3.0语言教程获取字符串长度 Swift3.0语言教程获取字符串长度,当在一个字符串中存在很多的字符时,如果想要计算字符串的长度时相当麻烦的一件事情,在NSString中可以使用length ...

  9. Xamarin基础命名空间Microsoft.SqlServer.Server

    Xamarin基础命名空间Microsoft.SqlServer.Server   该命名空间包含大量的类.接口和枚举,用于操作微软SQL Server数据库.该空间支持Xamarin.iOS和Xam ...

  10. maven 各种用途

    1.maven 管理项目编译 作为项目编译代码管理工具,可以方便的进行编译集成. 2. maven 扩展单元测试 扩展对接junit可以方便进行单元测试 3.maven profiles各种devel ...