在Infragistics可编辑的Wingrid上输入Key

本文关键字:输入 Key Wingrid Infragistics 编辑 | 更新日期: 2023-09-27 18:16:22

我有一个包含inffragistics窗口可编辑网格和winforms按钮的屏幕。按Enter键,新行被添加到超win网格中。相反,我需要触发winforms按钮事件。

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

在Infragistics可编辑的Wingrid上输入Key

您可以处理UltraGrid的BeforeRowUpdate事件,并在新行模板即将提交之前调用UltraGrid的perform click。

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;
    }
}