• 继承DataGridView


    代码
    public partial class DataGridViewEx : DataGridView
    {
    public delegate void ProcessEnterDeletegate();
    private event ProcessEnterDeletegate ProcessEnterDeletegateHandler;

    public DataGridViewEx()
    {
    InitializeComponent();
    }
    //public DataGridViewEx(ProcessEnterDeletegate del)
    //{
    // InitializeComponent();
    // ProcessEnterDeletegateHandler = del;
    //}

    public void SetHandler(ProcessEnterDeletegate del)
    {
    ProcessEnterDeletegateHandler
    = del;
    }

    protected override bool ProcessDialogKey(Keys keyData)
    {
    //是回车键
    if (keyData == (System.Windows.Forms.Keys.LButton | System.Windows.Forms.Keys.MButton | System.Windows.Forms.Keys.Back))
    {
    if (ProcessEnterDeletegateHandler != null) {
    ProcessEnterDeletegateHandler();
    }
    return true;
    }
    return base.ProcessDialogKey(keyData);
    }

    }



    /////////////// 调用页面///////////////////////

    public void SendKey()
    {
    SendKeys.Send(
    "{TAB}");
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    this.dataGridViewEx1.SetHandler(SendKey); //绑定处理程序
    this.dataGridViewEx1.Focus();
    this.f_sjzdTableAdapter.Fill(this.fSZJCM0420DataSet.F_sjzd);
    }

    //msdn的例子

    代码
    public class CustomDataGridView : DataGridView
    {
    [System.Security.Permissions.UIPermission(
    System.Security.Permissions.SecurityAction.LinkDemand,
    Window
    = System.Security.Permissions.UIPermissionWindow.AllWindows)]
    protected override bool ProcessDialogKey(Keys keyData)
    {
    // Extract the key code from the key value.
    Keys key = (keyData & Keys.KeyCode);

    // Handle the ENTER key as if it were a RIGHT ARROW key.
    if (key == Keys.Enter)
    {
    return this.ProcessRightKey(keyData);
    }
    return base.ProcessDialogKey(keyData);
    }

    [System.Security.Permissions.SecurityPermission(
    System.Security.Permissions.SecurityAction.LinkDemand, Flags
    =
    System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
    protected override bool ProcessDataGridViewKey(KeyEventArgs e)
    {
    // Handle the ENTER key as if it were a RIGHT ARROW key.
    if (e.KeyCode == Keys.Enter)
    {
    return this.ProcessRightKey(e.KeyData);
    }
    return base.ProcessDataGridViewKey(e);
    }
  • 相关阅读:
    5.数组的使用,最值和反转
    4.下标越界及小结
    3.数组的三种初始化及简单内存分析
    html5版 音乐播放器
    百度网盘搜索
    HTML5扩展之微数据与丰富网页摘要
    Java 学习文章汇总
    业余草
    Catalan数
    Luogu P3004 [USACO10DEC]宝箱Treasure Chest
  • 原文地址:https://www.cnblogs.com/wucg/p/1762249.html
Copyright © 2020-2023  润新知