找回密码
 立即注册

QQ登录

只需一步,快速开始

miyaminn

论坛元老

48

主题

121

帖子

2万

积分

论坛元老

积分
22182

活字格认证

miyaminn
论坛元老   /  发表于:2014-7-10 13:02  /   查看:7698  /  回复:8
当类型是Combobox类型的时候,Enter键就不会跳下一个单元格,
而是显示Combobox里面list的内容,现在想按Enter键跳到下一个
单元格。要如何实现呢?

8 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-7-10 18:41:00
沙发
回复 1楼miyaminn的帖子

请使用以下代码测试:

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


  11.             FarPoint.Win.Spread.InputMap inputmap1;
  12.             // Assign the InputMap object to the existing map.
  13.             inputmap1 = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
  14.             // Map the Enter key.
  15.             inputmap1.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
  16.             // Create another InputMap object.
  17.             FarPoint.Win.Spread.InputMap inputmap2;
  18.             // Assign this InputMap object to the existing map.
  19.             inputmap2 = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
  20.             // Map the Enter key.
  21.             inputmap2.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow);
复制代码
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2014-7-11 09:45:00
板凳
回复 2楼iceman的帖子

Dim im1 = vssDetail.GetInputMap(InputMapMode.WhenFocused)

                    Dim am = vssDetail.GetActionMap()

                    im1.Put(New Keystroke(Keys.Enter, Keys.None), "NewControlEnterAction")

                    Dim newAction As New NewControlEnterAction()

                    newAction.VssSpread = vssDetail
                    newAction.Flg = Not bPiIsReadOnly
                    am.Put("NewControlEnterAction", newAction)

                    Dim im2 = vssDetail.GetInputMap(InputMapMode.WhenAncestorOfFocused)

                    im2.Put(New Keystroke(Keys.Enter, Keys.None), "NewControlEnterAction")

Public Class NewControlEnterAction
    Inherits FarPoint.Win.Spread.Action

    Private _vssDetail As FarPoint.Win.Spread.FpSpread
    Private _rowIndex As Integer
    Private _colIndex As Integer
    Private _bFlg As Boolean = False
    Public Property VssSpread() As FarPoint.Win.Spread.FpSpread
        Get
            VssSpread = _vssDetail
        End Get
        Set(ByVal value As FarPoint.Win.Spread.FpSpread)
            _vssDetail = value
        End Set
    End Property

    Public WriteOnly Property Flg() As Boolean
        Set(ByVal Value As Boolean)
            _bFlg = Value
        End Set
    End Property
    Public Overrides Sub PerformAction(ByVal sender As Object)
        Dim lCol As Integer
        Dim lRow As Integer

        With _vssDetail.ActiveSheet
            lCol = _vssDetail.ActiveSheet.ActiveColumnIndex
            lRow = _vssDetail.ActiveSheet.ActiveRowIndex
            Do While (lRow <= .RowCount - 1)

                If IsOddLine(lRow) Then
                    lRow = lRow + 1
                Else
                    lRow = lRow - 1
                    lCol = lCol + 1
                End If
                If lCol > .ColumnCount - 1 Then
                    lRow = lRow + 2
                    lCol = 1
                End If
                If lRow > .RowCount - 1 Then
                    Exit Do
                End If

                If Not _bFlg Then
                    If .Cells(lRow, lCol).Locked = False And .Columns(lCol).Visible = True Then
                        If (lRow = 0 AndAlso lCol = 1) OrElse (lRow <> 0 AndAlso lCol = 2) OrElse _
                         lCol = 3 OrElse lCol = 8 Then
                            .SetActiveCell(lRow, lCol)
                            _vssDetail.EditMode = True
                        Else
                            .SetActiveCell(lRow, lCol)
                            _vssDetail.EditMode = False
                        End If
                        Exit Do
                    End If
                Else

                    If lCol = 6 AndAlso lRow Mod 2 = 0 Then
                        .SetActiveCell(lRow, lCol)
                        _vssDetail.EditMode = True
                        Exit Do
                    Else
                        If .Cells(lRow, lCol).Locked = False And .Columns(lCol).Visible = True Then
                            If (lRow = 0 AndAlso lCol = 1) OrElse (lRow <> 0 AndAlso lCol = 2) OrElse _
                             (lRow Mod 2 = 0 AndAlso lRow < 2 AndAlso lCol = 3) OrElse (lRow Mod 2 = 0 AndAlso lCol = 5) _
                             OrElse (lRow Mod 2 = 0 AndAlso lCol = 7) OrElse lCol = 8 Then
                                .SetActiveCell(lRow, lCol)
                                _vssDetail.ShowColumn(0, lCol, CType(FarPoint.Win.Spread.VerticalPosition.Bottom, HorizontalPosition))
                                _vssDetail.EditMode = True
                            ElseIf lRow Mod 2 <> 0 AndAlso lRow >= 2 AndAlso lCol = 3 Then
                                .SetActiveCell(lRow, lCol)
                                _vssDetail.ShowColumn(0, lCol, CType(FarPoint.Win.Spread.VerticalPosition.Bottom, HorizontalPosition))
                                _vssDetail.EditMode = True
                            Else
                                .SetActiveCell(lRow, lCol)
                                _vssDetail.ShowColumn(0, lCol, CType(FarPoint.Win.Spread.VerticalPosition.Bottom, HorizontalPosition))
                                _vssDetail.EditMode = False
                            End If
                            Exit Do
                        End If
                    End If
                End If
            Loop
        End With
    End Sub
    Private Function IsOddLine(ByVal liRow As Integer) As Boolean
        If (liRow Mod 2 = 0) Then
            IsOddLine = True
        Else
            IsOddLine = False
        End If
    End Function
End Class

现在第五列是Combobox列,enter按下后调到第五列就不往下跳了。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-7-11 17:25:00
地板
回复 3楼miyaminn的帖子

通过楼上代码我没能重现问题,请参考效果图:

Demo1.gif

附件是我的测试 Demo:
VS2013 + Spread for WinForms 7.0V3
13195_2.zip (83 KB, 下载次数: 393)
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2014-7-11 17:57:00
5#
回复 4楼iceman的帖子

当E列用鼠标选择后,文本框内的子会被全选,按enter键就会一值出现List内容,而不会跳到下一个单元格
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-7-11 18:19:00
6#
回复 5楼miyaminn的帖子

请问截图中的操作和你5#中的描述一致吗?

Demo2.gif

你的 Spread 版本是?
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2014-7-11 19:56:00
7#
回复 4楼iceman的帖子

还想知道一个问题,D列掉到E列时让E列Show里面的List内容,要怎么做呢?
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2014-7-11 19:57:00
8#
回复 6楼iceman的帖子

这个是一致的。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-7-14 14:59:00
9#
回复 4楼iceman的帖子

还想知道一个问题,D列掉到E列时让E列Show里面的List内容,......
miyaminn 发表于 2014-7-11 19:56:00


可以实现,这里有一段 C# 代码你可以参考下:
  1. private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             FarPoint.Win.Spread.CellType.ComboBoxCellType cmbocell = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
  4.             cmbocell.Items = (new String[] { &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot; });
  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].Columns[0].CellType = cmbocell;

  13.             fpSpread1.KeyDown += fpSpread1_KeyDown;

  14.         }

  15.         void fpSpread1_KeyDown(object sender, KeyEventArgs e)
  16.         {
  17.             fpSpread1.EditMode = true;

  18.             FpCombo combo = fpSpread1.EditingControl as FpCombo;

  19.             if (combo != null)

  20.                 combo.ShowList(true);
  21.         }
复制代码


为了给您提供更好的服务,请对本次服务做出评价,我们会认真对待您提出的宝贵意见。

评分

参与人数 1满意度 +5 收起 理由
miyaminn + 5 问题解决了,谢谢!

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部