回复 4楼qiuzhilv007的帖子
代码如下,看看哪些行为和你期望的不一样,咱们Case by case的搞定这个问题。
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- // 我没有装MRow,因此我没有Designer,以下代码为初始化代码。。。。。
- GcMultiRow mrow = new GcMultiRow();
- mrow.Dock = DockStyle.Fill;
- this.Controls.Add(mrow);
- GcNumberCell gcNumberCell1 = new GcNumberCell() { Name = "GcNumberCell1" };
- gcNumberCell1.DisplayFields.AddRange("####0", "", "", "-", "");
- gcNumberCell1.Fields.SetFields("#####", "", "", "-", "");
- Template t = Template.CreateGridTemplate(new Cell[] { gcNumberCell1 });
-
- mrow.Template = t;
- mrow.RowCount = 10;
- mrow.EditingControlShowing += mrow_EditingControlShowing;
- mrow.CellEndEdit += mrow_CellEndEdit;
- }
- void mrow_CellEndEdit(object sender, CellEndEditEventArgs e)
- {
- if (_lastEditingControl == null)
- {
- return;
- }
- _lastEditingControl.KeyDown -= editingControl_KeyDown;
- _lastEditingControl.KeyUp -= editingControl_KeyUp;
- _lastEditingControl.TextChanged -= editingControl_TextChanged;
- _lastEditingControl = null;
- }
- private GcNumberEditingControl _lastEditingControl = null;
- private Keys? _lastKeyStroke = null;
- void mrow_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
- {
- GcMultiRow mrow = sender as GcMultiRow;
- if (sender == null)
- {
- return;
- }
- if (mrow.CurrentCell.Name == "GcNumberCell1")
- {
- GcNumberEditingControl editingControl = e.Control as GcNumberEditingControl;
- if (editingControl == null)
- {
- return;
- }
- _lastEditingControl = editingControl;
- editingControl.KeyDown += editingControl_KeyDown;
- editingControl.KeyUp += editingControl_KeyUp;
- editingControl.TextChanged += editingControl_TextChanged;
- }
- }
- void editingControl_TextChanged(object sender, EventArgs e)
- {
- if (!_lastKeyStroke.HasValue)
- {
- // The text change is not caused by key
- return;
- }
- GcNumberEditingControl control = sender as GcNumberEditingControl;
- if (control == null)
- {
- return;
- }
- if (string.IsNullOrEmpty(control.Text))
- {
- control.Value = null;
- }
- }
- void editingControl_KeyUp(object sender, KeyEventArgs e)
- {
- _lastKeyStroke = null;
- }
- void editingControl_KeyDown(object sender, KeyEventArgs e)
- {
- _lastKeyStroke = e.KeyData;
- }
- }
复制代码 |