找回密码
 立即注册

QQ登录

只需一步,快速开始

chenf1980

论坛元老

41

主题

147

帖子

9349

积分

论坛元老

积分
9349

活字格认证

chenf1980
论坛元老   /  发表于:2011-6-4 17:46  /   查看:8920  /  回复:11
单元格是可编辑的,单元格的长度只有10,但是里面的字符串有20个长度。
鼠标点进去后,直接就拉到最右边了。 我想控制,鼠标点进去之后,最多只拉到单元格的长度,最右边的不显示出来。


如图,最左边是1111,结果拉到最右边去了

本帖子中包含更多资源

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

x

11 个回复

倒序浏览
neil
论坛元老   /  发表于:2011-6-7 11:07:00
沙发

回复 1# chenf1980 的帖子

我们推测你的MultiRow的EditMode属性是EditOnEnter。
就是当Cell获得焦点时,就进入编辑状态。
而且看你的情况,你是想要进入编辑状态之后还把所有文字选中的。

只需要处理GcMultiRow的EditingControlShowing事件,代码如下:
  1. Private Sub g_EditingControlShowing(sender As Object, e As EditingControlShowingEventArgs)
  2.         Dim t As TextBox = TryCast(e.Control, TextBox)
  3.         If t IsNot Nothing Then
  4.                 If Not t.IsHandleCreated Then
  5.                         t.CreateControl()
  6.                 End If
  7.                 t.BeginInvoke(New System.Action(Function() Do
  8.                         SendKeys.Send("{END}")
  9.                         SendKeys.Send("+{HOME}")
  10.                 End Function))
  11.         End If
  12. End Sub
复制代码

C#代码:
  1. void g_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
  2.         {
  3.             TextBox t = e.Control as TextBox;
  4.             if (t != null)
  5.             {
  6.                 if (!t.IsHandleCreated)
  7.                 {
  8.                     t.CreateControl();
  9.                 }        
  10.                 t.BeginInvoke(new System.Action(delegate()
  11.                 {                  
  12.                     SendKeys.Send("{END}");
  13.                     SendKeys.Send("+{HOME}");
  14.                 }));
  15.             }
  16.         }
复制代码
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-6-8 10:17:00
板凳
语法都通不过。。。
回复 使用道具 举报
neil
论坛元老   /  发表于:2011-6-8 11:04:00
地板

回复 3# chenf1980 的帖子

不好意思,vbcode中的确有个错误。:-D
  1. Private Sub g_EditingControlShowing(sender As Object, e As EditingControlShowingEventArgs)
  2.    Dim t As TextBox = TryCast(e.Control, TextBox)
  3.         If t IsNot Nothing Then
  4.             If Not t.IsHandleCreated Then
  5.                 t.CreateControl()
  6.             End If
  7.             t.BeginInvoke(New System.Action(Function()
  8.                                                 SendKeys.Send("{END}")
  9.                                                 SendKeys.Send("+{HOME}")
  10.                                             End Function))
  11.         End If
  12. End Sub
复制代码
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-6-8 11:57:00
5#


奇怪的,你那边是正确的吗?
我这么拷贝后,还是一大堆错误啊

本帖子中包含更多资源

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

x
回复 使用道具 举报
neil
论坛元老   /  发表于:2011-6-8 12:10:00
6#
我这的确是可以编译通过的。

本帖子中包含更多资源

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

x
回复 使用道具 举报
neil
论坛元老   /  发表于:2011-6-8 12:11:00
7#

回复 6# neil 的帖子

你贴出来的错误是没改之前的。 改过之后就没有问题了。:Z
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-6-8 12:41:00
8#
奇怪的,我就是用的你修改之后的啊。又确认了下,就是不行
回复 使用道具 举报
neil
论坛元老   /  发表于:2011-6-8 13:38:00
9#

回复 8# chenf1980 的帖子

可能你用的是.net 2.0 不支持上面写的匿名方法。
我改写了一下:
  1. Private Sub GcMultiRow1_EditingControlShowing(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
  2.         Dim t As TextBox = TryCast(e.Control, TextBox)
  3.         If t IsNot Nothing Then
  4.             If Not t.IsHandleCreated Then
  5.                 t.CreateControl()
  6.             End If
  7.             t.BeginInvoke(New Action(AddressOf Me.MoveCursor))
  8.         End If
  9.     End Sub
  10.     Private Sub MoveCursor()
  11.         SendKeys.Send("{END}")
  12.         SendKeys.Send("+{HOME}")
  13.     End Sub
复制代码
回复 使用道具 举报
chenf1980
论坛元老   /  发表于:2011-6-18 15:55:00
10#
Neil,我发现还是不对。
必须要在MultiRow模版里面,加上这么一句话

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
              MyBase.ProcessCmdKey(msg, keyData)

    End Function

这样才能实现效果,但是又不能加,因为加了之后,其他地方又出错了。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部