找回密码
 立即注册

QQ登录

只需一步,快速开始

qiuzhilv007

中级会员

34

主题

85

帖子

620

积分

中级会员

积分
620

活字格认证微信认证勋章

qiuzhilv007
中级会员   /  发表于:2015-11-18 11:30  /   查看:10753  /  回复:10
显示格式设为##0 编辑格式设为### 也就是编辑时输入0,显示时可看到0,进入编辑时是空白。
这样应该是NumberIntegerPartDisplayField的MinDigits设为1
然后在按下backspace或del按键时可以清空编辑和显示的两个状态。
这样是设置AllowDeleteToNull = true
在以上基础上,如何设置才能在编辑状态时,负数的情况下按下backspace键时不把负号删掉?
如把AllowDeleteToNull设为FALSE时,负号是不被删掉的,但也不能清空0的状态。

10 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-11-18 17:30:00
沙发
回复 1楼qiuzhilv007的帖子

谢谢您的反馈。
我们需要验证后给您反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Leo
超级版主   /  发表于:2015-11-18 17:38:00
板凳
回复 1楼qiuzhilv007的帖子

看样子你需要这么干:
1. 仍旧设置AllowDeleteToNull = FALSE
2. 写代码处理BackSpace或者Del按键,如果发现已经将GcNumberCellEditor上的文本删干净了,就直接将GcNumberCellEditor上的Value清空为Null

评分

参与人数 1金币 +999 收起 理由
Alice + 999 奖励金币

查看全部评分

回复 使用道具 举报
qiuzhilv007
中级会员   /  发表于:2015-11-19 10:37:00
地板
处理BackSpace时,在发现已经将GcNumberCellEditor上的文本删干净了这个时候已晚了,因为在按下backspace时,要删的数字还没有被删。
要判断还有一个数字时,但如果是负数时将GcNumberEditingControl.value设置为Nothing后,也一起把负号清掉了,且这个value是Decmail类型,在绑定datasource时应该赋值dbnull.value,但这个不能赋给decimal
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-11-19 17:50:00
5#
回复 4楼qiuzhilv007的帖子

您的问题我们收到了,测试后给您反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Leo
超级版主   /  发表于:2015-11-20 12:06:00
6#
回复 4楼qiuzhilv007的帖子

代码如下,看看哪些行为和你期望的不一样,咱们Case by case的搞定这个问题。
  1.    public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();

  6.             // 我没有装MRow,因此我没有Designer,以下代码为初始化代码。。。。。
  7.             GcMultiRow mrow = new GcMultiRow();

  8.             mrow.Dock = DockStyle.Fill;
  9.             this.Controls.Add(mrow);

  10.             GcNumberCell gcNumberCell1 = new GcNumberCell() { Name = "GcNumberCell1" };
  11.             gcNumberCell1.DisplayFields.AddRange("####0", "", "", "-", "");
  12.             gcNumberCell1.Fields.SetFields("#####", "", "", "-", "");

  13.             Template t = Template.CreateGridTemplate(new Cell[] { gcNumberCell1 });
  14.             
  15.             mrow.Template = t;

  16.             mrow.RowCount = 10;

  17.             mrow.EditingControlShowing += mrow_EditingControlShowing;
  18.             mrow.CellEndEdit += mrow_CellEndEdit;   
  19.         }

  20.         void mrow_CellEndEdit(object sender, CellEndEditEventArgs e)
  21.         {
  22.             if (_lastEditingControl == null)
  23.             {
  24.                 return;
  25.             }
  26.             _lastEditingControl.KeyDown -= editingControl_KeyDown;
  27.             _lastEditingControl.KeyUp -= editingControl_KeyUp;
  28.             _lastEditingControl.TextChanged -= editingControl_TextChanged;

  29.             _lastEditingControl = null;

  30.         }

  31.         private GcNumberEditingControl _lastEditingControl = null;
  32.         private Keys? _lastKeyStroke = null;

  33.         void mrow_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
  34.         {
  35.             GcMultiRow mrow = sender as GcMultiRow;
  36.             if (sender == null)
  37.             {
  38.                 return;
  39.             }

  40.             if (mrow.CurrentCell.Name == "GcNumberCell1")
  41.             {
  42.                 GcNumberEditingControl editingControl = e.Control as GcNumberEditingControl;
  43.                 if (editingControl == null)
  44.                 {
  45.                     return;
  46.                 }

  47.                 _lastEditingControl = editingControl;
  48.                 editingControl.KeyDown += editingControl_KeyDown;
  49.                 editingControl.KeyUp += editingControl_KeyUp;
  50.                 editingControl.TextChanged += editingControl_TextChanged;
  51.             }
  52.         }

  53.         void editingControl_TextChanged(object sender, EventArgs e)
  54.         {
  55.             if (!_lastKeyStroke.HasValue)
  56.             {
  57.                 // The text change is not caused by key
  58.                 return;
  59.             }

  60.             GcNumberEditingControl control = sender as GcNumberEditingControl;
  61.             if (control == null)
  62.             {
  63.                 return;
  64.             }

  65.             if (string.IsNullOrEmpty(control.Text))
  66.             {
  67.                 control.Value = null;
  68.             }
  69.         }

  70.         void editingControl_KeyUp(object sender, KeyEventArgs e)
  71.         {
  72.             _lastKeyStroke = null;
  73.         }

  74.         void editingControl_KeyDown(object sender, KeyEventArgs e)
  75.         {
  76.             _lastKeyStroke = e.KeyData;
  77.         }
  78.     }
复制代码

评分

参与人数 1金币 +999 满意度 +5 收起 理由
Alice + 999 + 5 thanks

查看全部评分

回复 使用道具 举报
Carl
版主   /  发表于:2015-11-20 12:17:00
7#
回复 1楼qiuzhilv007的帖子

我实验了一下,没发现楼主说的问题啊?
设置为:
            var cell = new GcNumberCell();
            cell.Fields.IntegerPart.MinDigits = 0;
            cell.DisplayFields.AddRange("###0", "", "", "-", "");
            cell.AllowDeleteToNull = false;
表现结果是,进入编辑状态,
如果Text为“-123”,那么按Backspace删除可以删掉后面的数字,符号删不掉;
如果Text为“0123”,那么按Backspace删除可以删掉所有的数字,包括0。

是我理解的不对,还是楼主没说清楚?

评分

参与人数 1金币 +999 收起 理由
Alice + 999 奖励金币

查看全部评分

愿 Engine 归于沉寂,Timer 停止运动,Message Queue 不再流淌,Data Source 为我掌握
回复 使用道具 举报
qiuzhilv007
中级会员   /  发表于:2015-11-26 14:55:00
8#
回复 7楼Carl的帖子

编辑状态下是清空了,这时结束编辑,进入显示状态看是否清空了?
显示状态是不是还是显示一个0,显示的0清不掉了
回复 使用道具 举报
qiuzhilv007
中级会员   /  发表于:2015-11-26 15:25:00
9#
回复 6楼Leo的帖子

谢谢提供思路。项目中对GcMultirow的事件根据业务进行了各种封装。修改方式有所限制
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-11-26 18:20:00
10#
回复 8楼qiuzhilv007的帖子

谢谢您的反馈。
我们测试后给您反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部