OT - User Control to Expand DataGridView Capabilities

OT - User Control to Expand DataGridView Capabilities

Old forum URL: forums.lhotka.net/forums/t/3591.aspx


josh.kodroff posted on Tuesday, September 25, 2007

Hey All,

I'm trying to create a user control that adds some extra stuff to the DataGridView (bottom statusbar with record count and top toolstrip with search and filter feature).

I read this tutorial from MSFT: http://msdn2.microsoft.com/en-us/library/ms233813(VS.80).aspx

I added the attributes and properties the tutorial told me to, but in the Windows Forms Designer, the DataSource property is greyed out and I don't understand why.

If I can't do all the things at design time with this user control (set a datasource and arrange columns) that I can do with a regular DGV, I'm going to have to do a lot more work.

Does anyone have any advice to help out?  Has anyone successfully created user controls that include the DGV?  Am I dumb for not going with a third party control?

Thanks!
JK

McManus replied on Wednesday, September 26, 2007

Josh,

To make your control behave in the designer like you're used to with BindingSource and DataGridView controls, add the following attributes to the DataSource and DataMember properties:

[ComplexBindingProperties("DataSource", "DataMember")]
public class MyUserControl : UserControl
{
      [Category("Data")]
      [AttributeProvider(typeof(IListSource))]
      public object DataSource { get; set; }

      [Category("Data")]
      [Editor(@"System.Windows.Forms.Design.DataMemberListEditor,
            System.Design, Version=2.0.0.0, Culture=neutral,
            PublicKeyToken=b03f5f7f11d50a3a"
, typeof(UITypeEditor))]
      public string DataMember { get; set; }
}

When you want to know more about DataBinding in WinForms 2.0, I recommend to take a look at this:
http://www.ubookcase.com/book/Addison.Wesley/Data.Binding.with.Windows.Forms.2.0.Programming.Smart.Client.Data.Applications.with.dot.NET/032126892x/main.html

Hope this helps,

Cheers,
Herman

josh.kodroff replied on Wednesday, September 26, 2007

Herman,

Still a no-go.  Both of the properties are greyed out in the Windows Forms designer. 

I'm really surprised that this is so difficult.  One would think that encapsulating the DGV in a user control would be a common operation.

JK

Copyright (c) Marimer LLC