Hi Mahender,
I think we need to answer the questions below:
1. What can the designer do for a component?
2. If the codes are generated as what you wanted, what will it result in?
My answers:
1. A component is an object, which has members and methods. The methods indicates what the component can do, however, the members stores its data which can be visited by some properties. The designer only provides a visual way to modify the data of a component via its properties and generates the relevant codes , nothing else. The values of the properties can be set in the properties window or by smart tags. When you set the value of the doType property, the designer only generates the codes to set the doType property, not including what has done in the set function. The designer cannot know the details of the set function of the doType property, because it can only see the interface of the component, which includes the properties that can be visited by other objects(the modifier is public or internal). For these reasons, the designer cannot generate codes as you wanted.
2. If the codes are generated, it will generate an incorrect result: the codes are actually executed twice. For example, the codes will be like this:
Me.MyComponent.doType = "type!"
Me.MyComponent.DS.Tables.Add("AutoTable")
In the first line, the table is added in the set function of the doType property. In the second line, the table is added again, which was incorrect.
Based on my understanding, you didn’t want the DataSet to be edited directly in the designer. You may only wanted the tables to be edited in the designer. You can hide the DataSet property and add another property to allow the designer to edit the tables in the designer as follows:
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
Public Property DS() As DataSet
Get
Return Me._DS
End Get
Set(ByVal value As DataSet)
Me._DS = value
End Set
End Property
Private _tables As List(Of DataTable) = New List(Of DataTable)
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Tables() As List(Of DataTable)
Get
Return _tables
End Get
End Property
You can add the tables into the DataSet after the InitializeComponent method was executed such as in the Load event handler of the form:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each dt As DataTable In Me.Cls_MyComponent1.Tables
Me.Cls_MyComponent1.DS.Tables.Add(dt)
Next
End Sub
Let me know if this helps.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.