【问题标题】:Enter Key on Infragistics Editable Wingrid在 Infragistics 可编辑 Wingrid 上输入键
【发布时间】:2016-11-04 10:56:12
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net infragistics ultrawingrid


    【解决方案1】:

    您可以处理 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      相关资源
      最近更新 更多