找回密码
 立即注册

QQ登录

只需一步,快速开始

814466854

注册会员

11

主题

29

帖子

92

积分

注册会员

积分
92

活字格认证微信认证勋章

814466854
注册会员   /  发表于:2013-11-21 19:20  /   查看:5056  /  回复:6
我想在CellBeginEdit的时候改变某个cell的可输入位数,在代码里应该怎么写?

6 个回复

倒序浏览
wedy.wang
初级会员   /  发表于:2013-11-22 09:33:00
沙发
看你具体用的什么Cell,如果是TextBoxCell,请设置MaxLength属性,就好了。
回复 使用道具 举报
814466854
注册会员   /  发表于:2013-11-22 10:59:00
板凳
回复 2楼wedy.wang的帖子


是TextBoxCell,现在就是编辑状态下只能输入6位,但表示的时候要8位表示,在Form代码中CurrentCell没有MaxLength的属性,只能在模板代码里写了方法调用了但还是表示了6位,求教啊~~



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
wedy.wang
初级会员   /  发表于:2013-11-22 11:15:00
地板
请使用下面的方法尝试一下:
Step1: 在Template当中设置TextBoxCell.MaxLength= 6
Step2:在Form中,处理GcMultiRow.CellFormatting事件,事件处理函数像下面一样:
       private void gcMultiRow1_CellFormatting(object sender, GrapeCity.Win.MultiRow.CellFormattingEventArgs e)
        {
            if (e.CellName == "textBoxCell1")
            {
                if (e.Value != null)
                {
                    e.Value = e.Value + "12";
                }
            }
        }

这样处理之后,在编辑状态最多输入6个字符,显示的时候可以多显示一个“12”,你根据自己的需求决定如何改造上面的处理函数吧。
回复 使用道具 举报
814466854
注册会员   /  发表于:2013-11-22 13:57:00
5#
版主,我试了,输入的时候还是可以输入8位的,可以把你的DEMO发我看看吗?
回复 使用道具 举报
wedy.wang
初级会员   /  发表于:2013-12-2 10:23:00
6#
不好意思,回复晚了。
请确保你已经在Template当中给Cell设置了MaxLength为6.
然后,请看下面的代码:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.gcMultiRow1.CellFormatting += gcMultiRow1_CellFormatting;
            this.gcMultiRow1.EditingControlShowing += gcMultiRow1_EditingControlShowing;
        }

        void gcMultiRow1_EditingControlShowing(object sender, GrapeCity.Win.MultiRow.EditingControlShowingEventArgs e)
        {
            if (this.gcMultiRow1.CurrentCellPosition.CellName == "textBoxCell1")
            {
                TextBox textBox = e.Control as TextBox;
                if (e.Control.Text.Length > textBox.MaxLength)
                {
                    int removeLength = e.Control.Text.Length - textBox.MaxLength;
                    e.Control.Text = e.Control.Text.Remove(textBox.MaxLength, removeLength);//确保编辑状态为6位。
                }
            }
        }
        void gcMultiRow1_CellFormatting(object sender, GrapeCity.Win.MultiRow.CellFormattingEventArgs e)
        {
            if (e.CellName == "textBoxCell1")
            {
                if (e.Value != null)
                {
                    e.Value = e.Value + "12";//增加两位
                }
            }
        }
    }
回复 使用道具 举报
814466854
注册会员   /  发表于:2013-12-4 15:08:00
7#
问题已解决,感谢版主!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部