在 Infragistics Editable Wingrid 上输入密钥

Enter Key on Infragistics Editable Wingrid

我有一个包含基础设施 windows 可编辑网格和 winforms 按钮的屏幕。 在 Enter 键上,新行被添加到 ultrawin 网格中。相反,我需要触发 winforms 按钮事件。

只有在选项卡上,它应该导航到下一个单元格,当它到达最后一个单元格时,它应该导航到下一行。

您可以处理 UltraGrid 的 BeforeRowUpdate 事件并在即将提交新行模板之前调用 UltraButton 的执行单击。

public partial class Form1 : Form
{
    private bool _IsEnterKeyDown = false;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        ultraGrid1.KeyDown += new KeyEventHandler(ultraGrid1_KeyDown);
        ultraGrid1.BeforeRowUpdate += new CancelableRowEventHandler(ultraGrid1_BeforeRowUpdate);
        ultraGrid1.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(ultraGrid1_InitializeLayout);
        ultraGrid1.DataSource = GetDataTable();
    }

    private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            _IsEnterKeyDown = true;
        }
    }

    private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
    {
        if (e.Row.IsAddRow && _IsEnterKeyDown)
        {
            _IsEnterKeyDown = false;
            ultraButton1.PerformClick();
        }
    }

    private void ultraButton1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Button click event raised!");
    }

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
    {
        e.Layout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom;
    }

    private DataTable GetDataTable(int rows = 10)
    {
        DataTable table = new DataTable("Table1");

        table.Columns.Add("Boolean column", typeof(bool));
        table.Columns.Add("Integer column", typeof(int));
        table.Columns.Add("DateTime column", typeof(DateTime));
        table.Columns.Add("String column", typeof(string));

        for (int i = 0; i < rows; i++)
        {
            DataRow row = table.NewRow();
            row["Boolean column"] = i % 2 == 0 ? true : false;
            row["Integer column"] = i;
            row["String column"] = "text";
            row["DateTime column"] = DateTime.Today.AddDays(i);
            table.Rows.Add(row);
        }

        return table;
    }
}