回复 14楼jplzj的帖子
稍微修改一下自定义的CellType类型:
- Public Class MyComboCellType
- Inherits FarPoint.Win.Spread.CellType.GeneralCellType
- Dim editor As FarPoint.Win.FpCombo
- Dim ItemSource As Dictionary(Of String, String)
- Public Sub New(ByVal data As Dictionary(Of String, String))
- ItemSource = data
- Dim l_Items As New List(Of String)
- Dim l_Itemdata As New List(Of String)
- For Each key As String In data.Keys
- l_Items.Add(data(key))
- l_Itemdata.Add(key)
- Next
- editor = New FarPoint.Win.FpCombo()
- editor.Editable = True
- editor.BorderStyle = BorderStyle.None
- editor.BackgroundColor = Color.White
- editor.List.AddRange(l_Items.ToArray())
- editor.ItemData.AddRange(l_Itemdata.ToArray())
- End Sub
- Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
- If Not value Is Nothing Then
- value = ItemSource(value.ToString())
- End If
- MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
- End Sub
- Public Overrides Function GetEditorControl(ByVal parent As System.Windows.Forms.Control, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) As System.Windows.Forms.Control
- Return editor
- End Function
- Public Overrides Function GetEditorValue() As Object
- If editor.SelectedIndex = -1 Then
- Return Nothing
- End If
- For Each key As String In ItemSource.Keys
- If ItemSource(key).Equals(editor.SelectedItem.ToString()) Then
- Return key
- End If
- Next
- Return Nothing
- End Function
- Public Overrides Sub SetEditorValue(ByVal value As Object)
- Dim index As Integer = -1
- If value Is Nothing Then
- editor.Text = ""
- editor.SelectedIndex = index
- Return
- End If
- For Each key As String In ItemSource.Keys
- index = index + 1
- If key.Equals(value.ToString()) Then
- editor.SelectedIndex = index
- Return
- End If
- Next
- End Sub
- End Class
复制代码 |