0

Problem:

I can add Columns to the datagridview(Dgv1) Control with FrmColEditor.

But serialize is not done.

After Rebuild, Columns disappeared.

picture

Here is my code

UserControl Code:

Public Class UserControl1
    <Editor(GetType(MyColumnEditor), GetType(UITypeEditor)), Category("Data")>
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
    Public ReadOnly Property Cols() As DataGridViewColumnCollection
        Get
            Return Dgv1.Columns
        End Get
    End Property

End Class

MyColumnEditor Code:


    Public Class MyColumnEditor
        Inherits System.Drawing.Design.UITypeEditor

        Public Overrides Function GetEditStyle(context As ITypeDescriptorContext) As UITypeEditorEditStyle
            Return UITypeEditorEditStyle.Modal
        End Function

        Public Overloads Overrides Function EditValue(context As ITypeDescriptorContext, provider As IServiceProvider, value As Object) As Object

            Dim editor_service As IWindowsFormsEditorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
            If editor_service Is Nothing Then Return Nothing
            FrmColEditor.cols = DirectCast(value, DataGridViewColumnCollection)
            editor_service.ShowDialog(FrmColEditor)
            Return FrmColEditor.cols

        End Function
    End Class

But Columns properties are not being displayed in the designer, and when I rebuild my project, it shows empty Dgv1 Control

evry1falls
  • 194
  • 4
  • 15
  • I suggest you assign a ParentControlDesigner to the DataGridView instead of trying to recreate the Columns collection Editor. See this: [UserControl with header and content - Allow dropping controls in content panel and Prevent dropping controls in header at design time](https://stackoverflow.com/a/50772584/7444103). Now, instead of a Panel (as shown there), assign to `ContentsPanel` your DataGridView (maybe also rename it :) and also use `TypeDescriptor.AddAttributes(this.[Your DataGridView], new DesignerAttribute(typeof(MyPanelDesigner)));`. Your DGV will be accessible and fully editable. – Jimi Jun 06 '20 at 19:23
  • Note that some properties are removed in the custom Designer (properties you don't want Users of your UserControl to change). Maybe you want to remove more. – Jimi Jun 06 '20 at 19:28

0 Answers0