zoukankan      html  css  js  c++  java
  • 封装DateTimePicker并使用绑定时遇到的问题

    请教各位高手:
    我想把一个控件封装起来.DateTimePicker
    因为他的value的类型为DateTime所以不可以为Null
    但是数据库里有一些日期是为空的.如离职日期
    现在我写了一个类继承至DateTimePicker
    使用public object Value覆盖了基类的Value方法
    这样它就可以为NULL了.
    在使用时.我使用的是绑定
    private MDateTimePicker dtpQuotationDate;
    this.dtpQuotationDate.DataBindings.Add("Value", this.bindingSource1, "QuotationDate");
    但是他一直只使用我这个类Value的Set方法,不使用我这个类的Value的Get方法,还是调动Base.Value.不知道为什么啊 ,请各位高手指点.谢谢!

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Windows.Forms;
    using System.ComponentModel;
    using System.Text.RegularExpressions;

    namespace WinUI
    {
        
    /// <summary>
        
    /// 用于处理DBNull问题的DateTimePicker
        
    /// </summary>

        public class MDateTimePicker :DateTimePicker
        
    {
            
    private object dateValue;
            
    public new string Text
            
    {
                
    get
                
    {
                    
    return this.dateValue.ToString();
                }

                
    set
                
    {
                    
    this.dateValue = value;
                }

            }

            
    public object Value
            
    {
                
    get
                
    {
                    
    if (dateValue==null)
                    
    {
                        Format 
    = DateTimePickerFormat.Custom; this.CustomFormat = " ";
                    }

                    
    else
                    
    {
                        
    this.Format = DateTimePickerFormat.Short;
                    }

                    
    return dateValue;
                }

                
    set
                
    {
                    dateValue 
    = value;
                    
    base.Value = Convert.ToDateTime(value);
                }

            }

            
    protected override void OnTextChanged(EventArgs e)
            
    {
                
    //base.OnTextChanged(e);
                
    //if (Convert.ToDateTime(Value) == MaxDate)
                
    //{
                
    //    Format = DateTimePickerFormat.Custom;
                
    //    CustomFormat = " ";
                
    //}
                
    //else
                
    //{
                
    //    Format = DateTimePickerFormat.Long;
                
    //}
            }

            
    protected override void OnClick(EventArgs e)
            
    {
                
    //base.OnClick(e);
                
    //onEdit();
            }

            
    protected override void OnKeyDown(KeyEventArgs e)
            
    {
                
    base.OnKeyDown(e);
                
    if (e.KeyCode == Keys.Delete)
                
    {
                    
    this.Value = null;
                }

                
    else
                
    {
                    
    //onEdit();
                }

            }

            
    private void onEdit()
            
    {
                Format 
    = DateTimePickerFormat.Long;
                Value 
    = DateTime.Now;
            }

            
        }

    }



     

    ---------------------------------------------------------------------
    每个人都是一座山.世上最难攀越的山,其实是自己.往上走,即便一小步,也有新高度
    .

    --做最好的自己,我能!!!

  • 相关阅读:
    vue使用elementui合并table
    使用layui框架导出table表为excel
    vue使用elementui框架,导出table表格为excel格式
    前台传数据给后台的几种方式
    uni.app图片同比例缩放
    我的博客
    【C语言】取16进制的每一位
    SharePoint Solution 是如何部署的呢 ???
    无效的数据被用来用作更新列表项 Invalid data has been used to update the list item. The field you are trying to update may be read only.
    SharePoint 判断用户在文件夹上是否有权限的方法
  • 原文地址:https://www.cnblogs.com/tonyepaper/p/1202308.html
Copyright © 2011-2022 走看看