how to add DataSource property to my user control

I want to add DataSource property to my user control. and let me to choose datasource just like DataGridView.

Public Class Class1
Inherits UserControl
Private uds As DataSet

Public Property uDataSource() As DataSet
Get
Return uds
End Get
Set(ByVal value As DataSet)
uds = value
End Set
End Property


End Class

if I use the code above, I can choose dataset at design view but can pass value, the error is:
"Object of type 'System.Windows.Forms.BindingSource' cannot be converted to type 'System.Data.DataSet'."

What should I do please give me some clues. Thanks!




Answer this question

how to add DataSource property to my user control

  • Soheil Amjadi

    When you set the value of your uDataSource be sure to set it to a Dataset in your project (not a BindingSource component)

    If you drill into the 'Other Data SOurces' node you need to pick the instance of the DataSet on your form - this should not error!

     

    hope that helps,

     

    Steve Stein

    VB Team



  • Henry Ong

    I typed something wrong, but I can't edit.
    It should be:
    if I use the code above, I can choose dataset at design view but fail to accept value, the error is:
    "Object of type 'System.Windows.Forms.BindingSource' cannot be converted to type 'System.Data.DataSet'."


  • how to add DataSource property to my user control