0
我有一個屏幕,其中包含infragistics窗口可編輯網格和winforms按鈕。 在Enter鍵上,新行被添加到ultrawin網格中。相反,我需要啓動winforms按鈕事件。Infragistics上的Enter鍵可編輯Wingrid
只有在選項卡上,它應該導航到下一個單元格,當它到達最後一個單元格時,它應該導航到下一行。
我有一個屏幕,其中包含infragistics窗口可編輯網格和winforms按鈕。 在Enter鍵上,新行被添加到ultrawin網格中。相反,我需要啓動winforms按鈕事件。Infragistics上的Enter鍵可編輯Wingrid
只有在選項卡上,它應該導航到下一個單元格,當它到達最後一個單元格時,它應該導航到下一行。
在新的行模板即將提交之前,您可以處理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;
}
}