找回密码
 立即注册

QQ登录

只需一步,快速开始

xaj21

注册会员

7

主题

31

帖子

72

积分

注册会员

积分
72

活字格认证

xaj21
注册会员   /  发表于:2014-4-23 17:03  /   查看:14481  /  回复:20
由于是移行项目,通过代码封装实现了在ComboBoxCell上按左右键进行列表值的变化,但是变化后的文本不是全选蓝色背景的全选状态,有什么办法能够将选择了的值的文本设为全选状态?

20 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-4-23 17:47:00
沙发
回复 1楼xaj21的帖子

ComboBoxCellType 本身没有提供这个功能,您那边能否获取这个变化事件?如果能,可以通过 fpSpread1.ActiveSheet.GetEditor 方法获取这个 Editor 进而选择文本。
回复 使用道具 举报
xaj21
注册会员   /  发表于:2014-4-23 18:10:00
板凳
Editor可以取到,调用StartEditing方法,没效果,能说的更仔细一点吗?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-4-24 12:20:00
地板
回复 3楼xaj21的帖子

不知道您指的封装都做了哪些操作,是否方便共享以便跟踪问题?
以下是我获取编辑器的代码:

  1.         private void 添加ComboCellTypeToolStripMenuItem_Click(object sender, EventArgs e)
  2.         {
  3.             FarPoint.Win.Spread.CellType.ComboBoxCellType cmbocell = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
  4.             cmbocell.Items = (new String[] { "January", "February", "March", "April", "May", "June" });
  5.             cmbocell.AcceptsArrowKeys = FarPoint.Win.SuperEdit.AcceptsArrowKeys.AllArrows;
  6.             cmbocell.AutoSearch = FarPoint.Win.AutoSearch.SingleCharacter;
  7.             cmbocell.Editable = true;
  8.             cmbocell.ListAlignment = FarPoint.Win.ListAlignment.Left;
  9.             cmbocell.ListOffset = 20;
  10.             cmbocell.ListWidth = 0;
  11.             cmbocell.MaxDrop = 4;
  12.             fpSpread1.Sheets[0].Cells[2, 2].CellType = cmbocell;

  13.             this.fpSpread1.EditModeOn += fpSpread1_EditModeOn;
  14.         }

  15.         void fpSpread1_EditModeOn(object sender, EventArgs e)
  16.         {
  17.             var fb = this.fpSpread1.EditingControl as FarPoint.Win.FpCombo;
  18.             fb.KeyDown += fb_KeyDown;
  19.         }

  20.         void fb_KeyDown(object sender, KeyEventArgs e)
  21.         {
  22.         }
复制代码
回复 使用道具 举报
xaj21
注册会员   /  发表于:2014-4-24 13:32:00
5#
封装的部分代码,通过这种方式实现的
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
            Dim isCommbox As Boolean = False
            If Me.ActiveSheet.ActiveCell IsNot Nothing AndAlso (TypeOf (Me.ActiveSheet.ActiveCell.CellType) Is CellType.ComboBoxCellType OrElse TypeOf (Me.ActiveSheet.ActiveColumn.CellType) Is CellType.ComboBoxCellType) Then
                isCommbox = True
                If keyData = Keys.Left Then
                    Dim comobBoxCellType As ComboBoxCellType = Me.ActiveSheet.ActiveColumn.CellType
                    Dim index As Integer = -1
                    For Each item As String In comobBoxCellType.Items
                        index = index + 1
                        If item.Equals(MyBase.ActiveSheet.ActiveCell.Value) Then Exit For
                    Next
                    If index = -1 Or index = 0 Then Return True
                    MyBase.ActiveSheet.ActiveCell.Value = comobBoxCellType.Items(index - 1)
                    Return True
                ElseIf keyData = Keys.Right Then
                    Dim comobBoxCellType As ComboBoxCellType = Me.ActiveSheet.ActiveColumn.CellType
                    Dim index As Integer = -1
                    For Each item As String In comobBoxCellType.Items
                        index = index + 1
                        If item.Equals(MyBase.ActiveSheet.ActiveCell.Value) Then Exit For
                    Next
                    If index = comobBoxCellType.Items.Count - 1 Then Return True
                    MyBase.ActiveSheet.ActiveCell.Value = comobBoxCellType.Items(index + 1)
                    Return True
                End If
            End If
End Function
回复 使用道具 举报
xaj21
注册会员   /  发表于:2014-4-24 14:07:00
6#
根据你前面的代码做了一下修正
  1. Dim isCommbox As Boolean = False
  2.             If Me.ActiveSheet.ActiveCell IsNot Nothing AndAlso (TypeOf (Me.ActiveSheet.ActiveCell.CellType) Is CellType.ComboBoxCellType OrElse TypeOf (Me.ActiveSheet.ActiveColumn.CellType) Is CellType.ComboBoxCellType) Then
  3.                                 isCommbox = True
  4.                                 Dim ctl As FarPoint.Win.FpCombo = Me.EditingControl
  5.                                 If keyData = Keys.Left Then
  6.                                         If ctl.SelectedIndex > 0 Then
  7.                                                 ctl.SelectedIndex = ctl.SelectedIndex - 1
  8.                                         End If
  9.                                         Return True
  10.                                 ElseIf keyData = Keys.Right Then
  11.                                         If ctl.SelectedIndex < ctl.ItemData.Count - 1 Then
  12.                                                 ctl.SelectedIndex = ctl.SelectedIndex + 1
  13.                                         End If
  14.                                         Return True
  15.                                 End If
  16.                         End If
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-4-24 15:28:00
7#
回复 6楼xaj21的帖子

请问现在问题解决了吧?
回复 使用道具 举报
xaj21
注册会员   /  发表于:2014-4-24 16:06:00
8#
还没有解决,不知道如何将选中的文本背景色变成蓝色背景全选状态。
刚才那些代码只是实现了按左右键能选中的文本。
無題.gif
右边图片就是按下左右键的效果(右边图片)
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-4-24 17:38:00
9#
回复 8楼xaj21的帖子

我通过 Spread 提供了 ComboCellType 可能无法解决您这个问题,能否把你的 Demo 发上来继续调查?
回复 使用道具 举报
xaj21
注册会员   /  发表于:2014-4-24 18:09:00
10#
附件是demo
WindowsApplication10.rar (88.64 KB, 下载次数: 2171)
回复 使用道具 举报
123下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部