Wisdombud.CommonTool及其应用
@(编程)
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及其应用的更多相关文章
- tomcat RMI 停不掉
项目采用jfinal框架,做了一个RMI的服务,对其它程序提供服务.实现上,写了一个RmiPlugin package com.wisdombud.cloudtalk.plugin; import j ...
- JAVA spring hibernate 多数据源配置记录
数据源配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...
- java spring 邮件发送
开发中经常会遇到发送邮件进行用户验证,或者其它推送信息的情况,本文基于spring,完成邮件的发送,主要支持普通文本邮件的发送,html文本邮件的发送,带附件的邮件发送,没有实现群发.多个附件发送等需 ...
- iOS 根据银行卡号判断银行名称
如何根据银行卡号判断银行名称? + (NSString *)getBankName:(NSString*) cardId{ //"发卡行.卡种名称", NSArray* bankN ...
- UNITY3D在线更新之道-CSlight 使用总结
转自:http://blog.csdn.net/leonwei/article/details/39233775 最近做U3D的热更新,研究了各种方式无果后,最容易最先想到的方式就是利用c#的反射机制 ...
- Hibernate入门(2)- 不用配置用注解
在上一个例子里面,我用的配置文件的方式,这次改成注解. pom.xml 增加了hibernate-commons-annotations和hibernate-annotations <proje ...
- OpenXML操作word
OpenXML概述 项目中经常需要操作word,之前的方式是采用COM接口,这个接口很不稳定,经常报错.现在开始采用OpenXML.OpenXML(OOXML)是微软在Office 2007中提出的一 ...
- c#通过操作mongodb gridfs实现文件的数据库存储
@(编程) 源码 using MongoDB.Driver; using MongoDB.Driver.GridFS; using System.IO; namespace Wisdombud.Mon ...
- C#下载http文件
@(编程) using System; using System.IO; using System.Net; namespace Wisdombud.Util { public class HttpH ...
随机推荐
- linux 多处理器概念
Linux 提出了 Multi-Processing 的概念,它的调度器可以将操作系统的线程均分到各个核(或硬件线程)上去执行,以此达到并行计算的目的,从而也可以极大地提高系统的性能. 实现计数器 1 ...
- css中图片的四种地址引用
URL: CSS中四种引用图片asset的方式:
- ionic2rc版常见的一些坑
1.config.xml里的包名不能有横杠,否则在build android的时候会报错 <widget id="com.ionicframework.name-abc" v ...
- [转]JavaScript 的性能优化:加载和执行
原文链接:http://www.ibm.com/developerworks/cn/web/1308_caiys_jsload/index.html?ca=drs- JavaScript 的性能优化: ...
- Python 删除 数组
numpy删除一列 从0开始,第三个参数是第几个维度 可以多删几个
- Fidder 监控WCF
Client端配置 <?xml version="1.0" encoding="utf-8" ?> <configuration> &l ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.1.系统界面报错Gnome
1.错误信息:登录系统后,屏幕弹出几个错误对话框,无菜单.无按钮 GConf error: Failed to contact configuration server; some possible ...
- aspose.word 查找文本并加下划线
private Run SplitRun(Run run, int position) { Run beforeRun = (Run)run.Clone(true); beforeRun.Text = ...
- 关于Servlet的PrintWriter 中文乱码问题
ps:servlet的PrintWriter和ServletOutputStream是不能同时使用的,同时使用会抛异常; PrintWriter是字符流.ServletOutputStream是字节流 ...
- 1、c#中可以有静态构造方法,而java中没有,例如在单例模式中c#可以直接在静态构造中实例化对象,而java不可以
1.c#中可以有静态构造方法,而java中没有,例如在单例模式中c#可以直接在静态构造中实例化对象,而java不可以