DataGridView 时间控件应用
来源:互联网 发布:鬼谷尸踪 有声小说软件 编辑:程序博客网 时间:2024/06/03 22:58
第一步
DateTimePickerm_zldtp = new DateTimePicker();
Rectanglem_zlRectangle;
publicUCWLZL()
{
InitializeComponent();
this.dgvZLData.Controls.Add(m_zldtp);//把时间控件加入DataGridView
m_zldtp.Visible = false;//先不让它显示
m_zldtp.Format = DateTimePickerFormat.Custom;
m_zldtp.CustomFormat = "yyyy-MM-dd";
m_zldtp.TextChanged += newEventHandler(m_zldtp_TextChange);//为时间控件加入事件dtp_TextChange
}
第二步
private void m_zldtp_TextChange(objectsender, EventArgs e)
{
this.dgvZLData.CurrentCell.Value= m_zldtp.Text;
}
第三步
privatevoid dgvZLData_CellClick(object sender,DataGridViewCellEventArgse)
{
try
{
if(e.ColumnIndex == 0) //如果DataGridView中第一列
{
m_zlRectangle =dgvZLData.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex,true); //得到所在单元格位置和大小
m_zldtp.Size = newSize(m_zlRectangle.Width,m_zlRectangle.Height);//把单元格大小赋给时间控件
m_zldtp.Location = newPoint(m_zlRectangle.X,m_zlRectangle.Y); //把单元格位置赋给时间控件
m_zldtp.Visible = true;//可以显示控件了
if(this.dgvZLData.CurrentCell.Value !=null && this.dgvZLData.CurrentCell.Value.Equals(DBNull.Value) ==false)
{
m_zldtp.Value = Convert.ToDateTime(this.dgvZLData.CurrentCell.Value);
}
else
{
m_zldtp.Value = DateTime.Now;
}
}
else
{
m_zldtp.Visible = false;
}
}
catch(Exception ex)
{
Class_Log4Net.WriteError("UCWLZL+dgvZLData_CellClick()" +ex.Message + ex.Source);
}
}
第四部
privatevoid dgvZLData_CellLeave(object sender,DataGridViewCellEventArgse)
{
if(e.ColumnIndex == 0)
{
if(this.dgvData.CurrentCell.Value ==null || this.dgvData.CurrentCell.Value.Equals(DBNull.Value) ==true)
{
this.dgvData.CurrentCell.Value= m_dtp.Text;
}
}
}
第五步
privatevoid dgvZLData_ColumnWidthChanged(object sender,DataGridViewColumnEventArgse)
{
m_zldtp.Visible = false;
}
privatevoid dgvZLData_Scroll(objectsender,ScrollEventArgs e)
{
m_zldtp.Visible = false;
}
- DataGridView 时间控件应用
- DataGridView控件 应用集锦
- C#DataGridView加时间控件
- c#datagridview中添加时间控件DateTimePicker
- DataGridView控件在vb.net中的应用
- 机房重构DataGridView控件应用
- DataGridView-添加一列为时间,加入时间控件Calender
- 时间控件应用
- 时间控件WdatePicker应用
- DataGridView 控件
- DataGridView控件
- DataGridView控件
- 自定义控件之DataGridView列(日期时间选择列)
- 自定义控件之DataGridView列(日期时间选择列)
- 时间查询、dataGridView控件、相对路径、数据库升序降序
- WinForm中关于DataGridView控件的一些应用
- c#如何实现在datagridview中加入时间控件、numericupanddown控件
- ext关于时间控件的应用
- lucene实现分组统计的方法
- jQuery_判断jQuery对象是否为null
- C++数据类型转换
- OpenCV1.0静态库编译
- android 学习教程(三)之---工程目录结构介绍
- DataGridView 时间控件应用
- HOST
- CST时间格式的转换
- Press any key to change color, do you want to try it. Please hurry up!
- Activity 本身调用finish() 然后显示之前的Activity 切换闪一下,不友好
- NSURLCache
- Oracle DataGuard数据备份方案详解
- Linux 下 Redis 安装及使用详情
- OpenCV编译为静态库的补充