Help!ComboBoxCellType

Posted by: caoweidehao on 8 September 2017, 12:56 pm EST

  • Posted 8 September 2017, 12:56 pm EST

    <U>when combobox's selectedindex has been changed, i hope that next cell will be selected.
    just as spread for com  to the same. please help me.</U>
    <SPAN class=kwd>Public Class</SPAN> mycombo
    <SPAN class=kwd>Inherits</SPAN> FarPoint.Win.Spread.CellType.ComboBoxCellType
    <SPAN class=kwd>Dim WithEvents</SPAN> c <SPAN class=kwd>As</SPAN> FarPoint.Win.FpCombo

    <SPAN class=kwd>Public Overrides Function</SPAN> GetEditorControl(<SPAN class=kwd>ByVal</SPAN> appearance <SPAN class=kwd>As</SPAN> FarPoint.Win.Spread.Appearance, <SPAN class=kwd>ByVal</SPAN> zoomFactor <SPAN class=kwd>As Single</SPAN>) <SPAN class=kwd>As</SPAN> System.Windows.Forms.Control
    c = <SPAN class=kwd>CType</SPAN>(<SPAN class=kwd>MyBase</SPAN>.GetEditorControl(appearance, zoomFactor), FarPoint.Win.FpCombo)
    <SPAN class=kwd>Return</SPAN> c
    <SPAN class=kwd>End Function

    Public Overrides Function</SPAN> IsReservedLocation(<SPAN class=kwd>ByVal</SPAN> g <SPAN class=kwd>As</SPAN> Graphics, <SPAN class=kwd>ByVal</SPAN> x <SPAN class=kwd>As Integer</SPAN>, <SPAN class=kwd>ByVal</SPAN> y <SPAN class=kwd>As Integer</SPAN>, <SPAN class=kwd>ByVal</SPAN> rc <SPAN class=kwd>As</SPAN> Rectangle, <SPAN class=kwd>ByVal</SPAN> appearance <SPAN class=kwd>As</SPAN> FarPoint.Win.Spread.Appearance, <SPAN class=kwd>ByVal</SPAN> value <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> zoomFactor <SPAN class=kwd>As Single</SPAN>) <SPAN class=kwd>As Object
    Dim</SPAN> rectButton <SPAN class=kwd>As New</SPAN> Rectangle(rc.X + rc.Width - SystemInformation.VerticalScrollBarWidth, rc.Y, SystemInformation.VerticalScrollBarWidth, rc.Height)
    <SPAN class=kwd>If</SPAN> rectButton.Contains(<SPAN class=kwd>New</SPAN> Point(x, y)) <SPAN class=kwd>Then
    Return Me
    Else
    Return Nothing
    End If
    End Function

    Private Sub</SPAN> c_KeyPress(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.Windows.Forms.KeyPressEventArgs) <SPAN class=kwd>Handles</SPAN> c.KeyPress
    <SPAN class=kwd>If</SPAN> c.Editable = <SPAN class=kwd>False AndAlso</SPAN> c.SelectionLength = Len(c.Text) <SPAN class=kwd>Then
    For</SPAN> i <SPAN class=kwd>As Integer</SPAN> = 0 <SPAN class=kwd>To</SPAN> c.List.Count - 1
    <SPAN class=kwd>If CStr</SPAN>(c.List(i)).IndexOf(e.KeyChar) = 0 <SPAN class=kwd>Then</SPAN>
    c.SelectedIndex = i
    c.SelectionStart = 0
    c.SelectionLength = Len(c.Text)
    e.Handled = <SPAN class=kwd>True
    Exit For
    End If
    Next
    End If
    End Sub


    Private Sub</SPAN> c_SelectedIndexChanged(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.EventArgs) <SPAN class=kwd>Handles</SPAN> c.SelectedIndexChanged
    <SPAN class=kwd>Dim</SPAN> cSpread <SPAN class=kwd>As</SPAN> FarPoint.Win.Spread.FpSpread
    cSpread = <SPAN class=kwd>CType</SPAN>(c.Parent, FarPoint.Win.Spread.FpSpread)
    <SPAN class=kwd>If Not</SPAN> cSpread <SPAN class=kwd>Is Nothing Then
    Dim</SPAN> intRow <SPAN class=kwd>As Integer</SPAN> = cSpread.ActiveSheet.ActiveRowIndex
    <SPAN class=kwd>Dim</SPAN> intCol <SPAN class=kwd>As Integer</SPAN> = cSpread.ActiveSheet.ActiveColumnIndex
    <SPAN class=kwd>Dim</SPAN> intMaxCol <SPAN class=kwd>As Integer</SPAN> = 0
    <SPAN class=kwd>Dim</SPAN> intMaxRow <SPAN class=kwd>As Integer</SPAN> = 0

    <SPAN class=kwd>For</SPAN> i <SPAN class=kwd>As Integer</SPAN> = cSpread.ActiveSheet.ColumnCount - 1 <SPAN class=kwd>To</SPAN> 0 <SPAN class=kwd>Step</SPAN> -1
    <SPAN class=kwd>If</SPAN> cSpread.ActiveSheet.Columns(i).Visible <SPAN class=kwd>Then</SPAN>
    intMaxCol = i
    <SPAN class=kwd>Exit For
    End If
    Next

    For</SPAN> i <SPAN class=kwd>As Integer</SPAN> = cSpread.ActiveSheet.RowCount - 1 <SPAN class=kwd>To</SPAN> 0 <SPAN class=kwd>Step</SPAN> -1
    <SPAN class=kwd>If</SPAN> cSpread.ActiveSheet.Rows(i).Visible <SPAN class=kwd>Then</SPAN>
    intMaxRow = i
    <SPAN class=kwd>Exit For
    End If
    Next

    If</SPAN> intCol < intMaxCol <SPAN class=kwd>Then</SPAN>
    intCol = intCol + 1
    <SPAN class=kwd>ElseIf</SPAN> intRow < intMaxRow <SPAN class=kwd>Then</SPAN>
    intRow = intRow + 1
    intCol = 0
    <SPAN class=kwd>Else
    Exit Sub
    End If</SPAN>
    cSpread.ActiveSheet.SetActiveCell(intRow, intCol)
    <SPAN class=kwd>End If
    End Sub

    End Class</SPAN>
     
  • Replied 8 September 2017, 12:56 pm EST

    Hello,


    This code is working for me. What issue(s) are you having with the code?

  • Replied 8 September 2017, 12:56 pm EST

    sorry,i means that if it have other more simplily solution to this question.(move to next cell ).


    <DIV id=result_box>Another question is</DIV>
    <DIV> when the combobox is diseditable </DIV>
    <DIV>how can the cell's selectionlenth is combobox's width but not text's length  .</DIV>
  • Replied 8 September 2017, 12:56 pm EST

    Hello,


    1) There is not an easier way to implement this. You need to set the Active cell after selecting the item.


    2) If the Editable property is set to False, then the combobox celltype should act like a DropDownList instead of a Combobox and the selection should be the entire width of the cell and not just the text.

  • Replied 8 September 2017, 12:56 pm EST

    <DIV id=result_box>Thank you for your help</DIV>

    but Dropdownlist only for web?


    I am in win's development.


     

  • Replied 8 September 2017, 12:56 pm EST

    Hello,


    No. A DropDownListBox is the same as a non editable Combobox. This could be Windows or Web.

  • Replied 8 September 2017, 12:56 pm EST

    For issue 1 I'm wondering why you're not simply catchign the ComboSelChange event and moving the active cell from there. There shouldn't be a need to override the celltype to do this.

  • Replied 8 September 2017, 12:56 pm EST

    i need that cell  leave to next cell  whenever the combobox's dropdownlist has been clicked .

  • Replied 8 September 2017, 12:56 pm EST

    I see.


    May be the version's problem 


    Thanks a lot.


     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels