| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- namespace Core.StlMes
- {
- public partial class FormGridKeyDown : Form
- {
- public FormGridKeyDown()
- {
- InitializeComponent();
- }
- private void FormGridKeyDown_Load(object sender, EventArgs e)
- {
- //setColumnNoEdit();
- initData();
- }
- private void setColumnNoEdit()
- {
- foreach (UltraGridColumn c in ultraGrid1.DisplayLayout.Bands[0].Columns)
- {
- c.CellActivation = Activation.NoEdit;
- }
- }
- private void initData()
- {
- DataRow dr = null;
- for (int i = 0; i < 5; i++)
- {
- dr = dataTable1.NewRow();
- for (int j = 0; j < 5; j++)
- {
- dr[j] = (i + 1).ToString();
- }
- dataTable1.Rows.Add(dr);
- }
- for (int i = 0; i < 5; i++)
- {
- dr = dataTable2.NewRow();
- for (int j = 0; j < 5; j++)
- {
- dr[j] = (i + 1).ToString();
- }
- dataTable2.Rows.Add(dr);
- dr = dataTable2.NewRow();
- for (int j = 0; j < 5; j++)
- {
- dr[j] = (i + 1).ToString();
- }
- dataTable2.Rows.Add(dr);
- dr = dataTable2.NewRow();
- for (int j = 0; j < 5; j++)
- {
- dr[j] = (i + 1).ToString();
- }
- dataTable2.Rows.Add(dr);
- }
- }
- private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
- {
- int deviation = 3;
-
- try
- {
- UltraGrid grid = (UltraGrid)sender;
- if (grid.ActiveCell != null)
- {
- Rectangle rect = grid.ActiveCell.GetUIElement().Rect;
- switch (e.KeyCode)
- {
- case Keys.Up:
- rect.X = rect.X + deviation;
- rect.Y = rect.Y - deviation;
- e.Handled = true;
- break;
- case Keys.Down:
- case Keys.Enter:
- rect.X = rect.X + deviation;
- rect.Y = rect.Y + rect.Height + deviation;
- e.Handled = true;
- break;
- case Keys.Left:
- Left:
- rect.X = rect.X - deviation;
- rect.Y = rect.Y + deviation;
- e.Handled = true;
- break;
- case Keys.Right:
- Right:
- rect.X = rect.X + rect.Width + deviation;
- rect.Y = rect.Y + deviation;
- e.Handled = true;
- break;
- case Keys.Tab:
- if (e.Shift)
- {
- goto Left;
- }
- else
- {
- goto Right;
- }
- break;
- }
- UIElement myUIElement = this.ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(new Point(rect.X,rect.Y));
- UltraGridCell cell = (UltraGridCell)myUIElement.GetContext(typeof(UltraGridCell));
- if (cell != null && e.Handled)
- {
- ultraGrid1.ActiveCell = cell;
- }
-
- grid.PerformAction(UltraGridAction.EnterEditMode);
- }
- }
- catch (Exception ex)
- {
- //CoreWriteLogFileBase.WriteLog(ex.Message, "", "样式错误", LogInfoLevel.Error);
- }
- }
- private void ultraGrid1_KeyPress(object sender, KeyPressEventArgs e)
- {
- e.Handled = false;
- }
- private void ultraGrid1_ClickCell(object sender, ClickCellEventArgs e)
- {
- Rectangle rect =e.Cell.GetUIElement().Rect;
- //MessageBox.Show(rect.X.ToString() + " , " + rect.Y.ToString() + " , " + rect.Width.ToString() + " , " + rect.Height.ToString());
- }
- }
- }
|