以解决,发出共享。
Imports System
Imports System.ComponentModel
Imports System.Runtime.Serialization
Imports System.Security.Permissions
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Drawing
Imports FarPoint.Win
Imports FarPoint.Win.SuperEdit
Imports System.Globalization
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms.VisualStyles
<Serializable()> _
Public Class MyComboCellType
Inherits FarPoint.Win.Spread.CellType.GeneralCellType
Implements ISerializeSupport
Dim editor As FarPoint.Win.FpCombo
Dim ItemSource As Dictionary(Of String, String)
Public Sub New()
End Sub
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
Try
value = ItemSource(value.ToString())
Catch ex As Exception
End Try
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
Dim ItemsourceString As String = ""
Public Overrides Function Serialize(ByVal w As XmlTextWriter) As Boolean
w.WriteElementString("ItemSource", ItemsourceString)
w.WriteElementString("_Dictionaryname", _Dictionaryname)
MyBase.Serialize(w)
End Function
Public Overrides Function Deserialize(ByVal r As XmlNodeReader) As Boolean
' MessageBox.Show("Deserialize" & ItemsourceString)
MyBase.Deserialize(r)
End Function
Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
Me.ItemsourceString = info.GetString("ItemSource")
Dim data As New Dictionary(Of String, String)
data.Add(ItemsourceString.Split(":")(1), ItemsourceString.Split(":")(0))
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 GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
For Each key As String In ItemSource.Keys
ItemsourceString = ItemSource(key) & ":" & key
Next
info.AddValue("ItemSource", ItemsourceString)
MyBase.GetObjectData(info, context)
End Sub
End Class |