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 ...
随机推荐
- MVC+Ef项目(2) 如何更改项目的生成顺序;数据库访问层Repository仓储层的实现
我们现在先来看看数据库的生成顺序 居然是 Idal层排在第一,而 web层在第二,model层反而在第三 了 我们需要把 coomon 公用层放在第一,Model层放在第二,接下来是 Idal ...
- HDU 1496 Train Problem I 火车问题1(桟,水)
题意: 给出两个串,串中的数字i 代表编号为i的火车进入车站的顺序,车站如桟一样,先进后出.第二个串是火车出站的顺序,问若按照第一个串那样进站,是否有可能如第二个串一样的出站顺序?火车顶多9辆,即1- ...
- 并行编译 Xoreax IncrediBuild
好东西... http://pan.baidu.com/s/1BtZ4s
- 【阅读】提问的智慧+有效的报告BUG
这两项可谓是我们测试人员的基本要求了,不过实话说的是,我自己这两方面很薄弱.哎!!! 这两篇文章都看过了,不过我在这也记个笔记吧.督促自己!!! <提问的智慧> <如何有效地报告Bu ...
- ORACLE RAC集群硬件资源管理与单节点的区别
硬件资源是由OS kernel管理的,应用软件是不能直接访问硬件的,必须通过OS kernel提供的API接口间接访问,OS kernel 除了要完成用户的请求,还通过进程调度等机制来控制多进程对资源 ...
- 如何在VMware虚拟机间建立共享磁盘?
在同一台电脑上,有时难免要安装多个虚拟机,存储空间就成了最大的问题,那么如何解决虚拟机的硬盘问题呢,Vmware自带的工具可以很好的解决此问题,下面我们就来看看如何在Vmware虚拟机间建立共享磁盘? ...
- Android Bitmap实战技巧
注:本文大量参考谷歌官方文档自http://developer.android.com/intl/zh-cn/training/displaying-bitmaps/index.html.如果你自学能 ...
- WORD中如何让前两页不显示页码
WORD中如何让前两页不显示页码 上稿人:ojn 点击率: 15191 我们有时在用word编辑文档时,会遇上第一.二页无需显示页码,第三页才是正文的第一页时,该如何正确插入页码呢? 以wor ...
- hdu 1527(威佐夫博奕)
题意:容易理解. 分析:威佐夫博奕的模板题. 代码实现: #include<stdio.h> #include<string.h> #include<math.h> ...
- [转] Asp.Net 导出 Excel 数据的9种方案
湛刚 de BLOG 原文地址 Asp.Net 导出 Excel 数据的9种方案 简介 Excel 的强大之处在于它不仅仅只能打开Excel格式的文档,它还能打开CSV格式.Tab格式.website ...