Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Declaring properties on custom control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Resolved [RESOLVED] [2005] Declaring properties on custom control

    I am creating a custom control with a gridview on it along with a databindingsource and a databindingnavigator. I have created a custom property datasource, but am stuck on how to add the "new" feature to it so that it can find/create a datasource......

    This is what I have so far.

    VB Code:
    1. <Category("Data"), _
    2.     Description("Indicates the Source of the Control"), _
    3.     RefreshProperties(RefreshProperties.Repaint), AttributeProvider(GetType(IListSource))> _
    4.     Public Property DataSource() As Object
    5.         Get
    6.             Return (Me.dgvEditSearchPanel.DataSource)
    7.         End Get
    8.         Set(ByVal value As Object)
    9.             Me.dgvEditSearchPanel.DataSource = value
    10.         End Set
    11.     End Property
    12.  
    13.     <Category("Data"), _
    14.     Description("Indicates a sub-list of the data source to show in the control.")> _
    15.     Public Property Datamember() As String
    16.         Get
    17.             Return Me.dgvEditSearchPanel.DataMember
    18.         End Get
    19.         Set(ByVal value As String)
    20.             Me.dgvEditSearchPanel.DataMember = value
    21.         End Set
    22.     End Property

    Thank you!

    D
    Last edited by dminder; Dec 21st, 2006 at 04:40 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Declaring properties on custom control

    I suggest that you get yourself .NET Reflector so that you can look inside the Framework, and other, assemblies. It's useful for all sorts of things, including seeing what attributes are applied to various members. The DataGridView.DataSource property is decorated with the AttributeProvider attribute like so:
    AttributeProvider(GetType(IListSource))
    I would guess that that is what controls the behaviour that allows you to pick a data source in the designer. The DataMember property is decorated with the Editor attribute like so:
    Editor("System.Windows.Forms.Design.DataMemberListEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Declaring properties on custom control

    I downloaded that resource, although I am finding that it is a bit confusing to work with. Thank you for that addition to Datamember that gives me the same type list that datasource has to work with. Also, I have included AttributeProvider in the DataSource declaration. I have not found anything more yet so if you or anybody else has some additional insight it is greatly appreciated.

    Oh and Happy Holidays to all of you (who celebrate it anyways)!!

    D

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Declaring properties on custom control

    After alot more digging i found the answer. It is in a somewhat related article found here:

    http://msdn.microsoft.com/library/de...et02252003.asp

    the code i needed is this:
    VB Code:
    1. TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")

    For anybody who wants to create a databound control, I think this article rocks. Good luck and marking this thread resolved......

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Declaring properties on custom control

    Nice link. I've bookmarked that myself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width