Start New Discussion within our Software Development Community


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


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)
    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)
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()
        BFormat.Serialize(MStream, CurrentObject)
        Return MStream.ToArray()
    Catch e As Runtime.Serialization.SerializationException
        Return Nothing
    End Try
End Function

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

Thanks in advance.

This article has been dead for over six months. Start a new discussion instead.