@(编程)

1. 用法

student类

using System.ComponentModel;

namespace WindowsFormsApplication1
{
public class Student
{
public string Id { get; set; }
[DisplayName("姓名")]
public string Name { get; set; }
[DisplayName("性别")] public string Gender { get; set; } [DisplayName("年级")]
public string Grade { get; set; } [DisplayName("班级")]
public string Grade111 { get; set; } }
}

应用

using System;
using System.Collections.Generic;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
List<Student> data = new List<Student>();
Student s1 = new Student() { Id = Guid.NewGuid().ToString(), Gender = "男", Grade = "一年级", Name = "小王" };
data.Add(s1);
List<string> hideList = new List<string>();
hideList.Add("Id");
this.wDataGridView1.MyDataList = data;
this.wDataGridView1.MyHideList = hideList;
this.wDataGridView1.MyType = typeof(Student);
this.wDataGridView1.Repaint();
Student entity = this.wDataGridView1.GetSelect0BindItem() as Student;
MessageBox.Show(entity.Name);
}
}
}

2. 源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace Wisdombud.CommonTool.UI
{
public partial class WDataGridView : DataGridView
{
public IEnumerable<Object> MyDataList { get; set; }
public Type MyType { get; set; }
public IEnumerable<string> MyHideList { get; set; }
public WDataGridView()
{
InitializeComponent();
this.Init();
}
public WDataGridView(Type MyType, IEnumerable<Object> MyDataList, IEnumerable<string> MyHideList)
{
this.MyType = MyType;
this.MyHideList = MyHideList;
this.MyDataList = MyDataList;
InitializeComponent();
this.Init();
}
private void Init()
{
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.EditMode = DataGridViewEditMode.EditProgrammatically;
this.RowHeadersVisible = false;
this.Dock = DockStyle.Fill;
this.BackgroundColor = System.Drawing.SystemColors.Control;
}
public WDataGridView(IContainer container)
{
container.Add(this);
InitializeComponent();
this.Init();
}
public Object GetSelect0BindItem()
{
if (this.SelectedRows.Count == 0)
{
return null;
}
return this.SelectedRows[0].DataBoundItem;
}
public void Repaint()
{
if (this.MyHideList == null)
{
this.MyHideList = new List<string>();
}
this.DataSource = this.MyDataList;
if (this.MyDataList != null && this.MyType != null)
{
int i = 0;
foreach (PropertyInfo pi in MyType.GetProperties())
{
string captionName = pi.Name;
object[] objs = pi.GetCustomAttributes(typeof(DisplayNameAttribute), true);
if (this.Columns.Count <= i)
{
return;
}
this.Columns[i].Visible = true;
if (this.MyHideList.Contains(pi.Name))
{
this.Columns[i].Visible = false;
}
else
{
this.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
if (objs.Length > 0)
{
captionName = ((DisplayNameAttribute)objs[0]).DisplayName;
}
this.Columns[i].HeaderText = captionName;
}
i++;
if (i == this.Columns.Count)
{
break;
}
}
}
}
}
}

Wisdombud.CommonTool及其应用的更多相关文章

  1. tomcat RMI 停不掉

    项目采用jfinal框架,做了一个RMI的服务,对其它程序提供服务.实现上,写了一个RmiPlugin package com.wisdombud.cloudtalk.plugin; import j ...

  2. JAVA spring hibernate 多数据源配置记录

    数据源配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  3. java spring 邮件发送

    开发中经常会遇到发送邮件进行用户验证,或者其它推送信息的情况,本文基于spring,完成邮件的发送,主要支持普通文本邮件的发送,html文本邮件的发送,带附件的邮件发送,没有实现群发.多个附件发送等需 ...

  4. iOS 根据银行卡号判断银行名称

    如何根据银行卡号判断银行名称? + (NSString *)getBankName:(NSString*) cardId{ //"发卡行.卡种名称", NSArray* bankN ...

  5. UNITY3D在线更新之道-CSlight 使用总结

    转自:http://blog.csdn.net/leonwei/article/details/39233775 最近做U3D的热更新,研究了各种方式无果后,最容易最先想到的方式就是利用c#的反射机制 ...

  6. Hibernate入门(2)- 不用配置用注解

    在上一个例子里面,我用的配置文件的方式,这次改成注解. pom.xml 增加了hibernate-commons-annotations和hibernate-annotations <proje ...

  7. OpenXML操作word

    OpenXML概述 项目中经常需要操作word,之前的方式是采用COM接口,这个接口很不稳定,经常报错.现在开始采用OpenXML.OpenXML(OOXML)是微软在Office 2007中提出的一 ...

  8. c#通过操作mongodb gridfs实现文件的数据库存储

    @(编程) 源码 using MongoDB.Driver; using MongoDB.Driver.GridFS; using System.IO; namespace Wisdombud.Mon ...

  9. C#下载http文件

    @(编程) using System; using System.IO; using System.Net; namespace Wisdombud.Util { public class HttpH ...

随机推荐

  1. file类型允许的文件格式设置问题,“选择文件”打开缓慢

    1,file类型的input对于打开的选择框的属性是由以下两个属性控制的: ①multiple="multiple" :一次可以选择多个文件 ②accept="image ...

  2. codeforces 510 C Fox And Names【拓扑排序】

    题意:给出n串名字,表示字典序从小到大,求符合这样的字符串排列的字典序 先挨个地遍历字符串,遇到不相同的时候,加边,记录相应的入度 然后就是bfs的过程,如果某一点没有被访问过,且入度为0,则把它加入 ...

  3. redis接入sentinelPool的配置

    package com.netease.mobile.commonUtil; import java.util.ArrayList; import java.util.HashSet; import ...

  4. UVALive 5532 King(差分约束,spfa)

    题意:假设一个序列S有n个元素,现在有一堆约束,限制在某些连续子序列之和上,分别有符号>和<.问序列S是否存在?(看题意都看了半小时了!) 注意所给的形式是(a,b,c,d),表示:区间之 ...

  5. Android之判断某个服务是否正在运行的方法

    /** * 判断某个服务是否正在运行的方法 * * @param mContext * @param serviceName * 是包名+服务的类名(例如:net.loonggg.testbackst ...

  6. (六)6.4 Neurons Networks Autoencoders and Sparsity

    BP算法是适合监督学习的,因为要计算损失函数,计算时y值又是必不可少的,现在假设有一系列的无标签train data:  ,其中 ,autoencoders是一种无监督学习算法,它使用了本身作为标签以 ...

  7. 一条sql导致数据库整体性能下降的诊断和解决的全过程

    今天早上一来,数据库load就比往常高了许多.想想数据库唯一的变化是昨天早上我曾经重新分析过数据库对象. [@more@] 发现数据库load很高,首先看top发现没有特别异常的进程,在数据库中适时抓 ...

  8. html:唤起手机qq开始对话 & 自动拨号

    <a href="mqqwpa://im/chat?chat_type=wpa&uin=[qq号]&version=1">XXX</a> 另 ...

  9. php 处理透明背景的图片时的问题

    PHP图象处理之透明背景的gif和png图片的一些问题 1,直接读取有透明背景的PNG格式文件,然后直接输出,背景变成了黑色,gif则没有这种情况.   解决方法:使用 imagesavealpha ...

  10. linux xampp eclipse xdebug 无法进入断点

    一.xampp 版本 1.8.3-5 xampp安装后会自动集成xdebug,目录一般为 /opt/lampp/lib/php/extensions/***-debug-***目录 关于php 与ph ...