Hi,

Can anyone help me on how to serialize an inherited datagridviewtextboxcell? I had created a custom cell in which I had incorporated several customized properties and save it to binary file.

<Serializable()> _
public class CustomTextboxCell
    Inherits Windows.Forms.DataGridViewTextBoxCell
    'code goes here
End Class

SaveFile:

Private Sub save()
    For Each TempCell As Windows.Forms.DataGridViewRow In Me.DataGridViewX1.Rows
        Dim xxx As Libraries.EntryCell = TempCell.Cells(0)
        xy.Add(xxx.FieldName, xxx)
    Next
    Dim TempIO As New IO.FileStream("D:\config.mbp", IO.FileMode.Create, IO.FileAccess.Write)
    Dim writeBinay As New IO.BinaryWriter(TempIO)
    Dim TempByte As Byte() = ObjectToBytes(xy)
    writeBinay.Write(TempByte)
     writeBinay.Close()
End Sub

Public Function ObjectToBytes(ByVal CurrentObject As [Object]) As Byte()
    Dim MStream As New IO.MemoryStream()
    Dim BFormat As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
    Try
        BFormat.Serialize(MStream, CurrentObject)
        Return MStream.ToArray()
    Catch e As Runtime.Serialization.SerializationException
        Return Nothing
    Finally
    MStream.Close()
    End Try
End Function

I am getting and error of "Type 'System.Windows.Forms.DataGridViewTextBoxCell' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable." upon saving it to binary file.

Thanks in advance.

Can anyone help me on this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.