Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / August 2005

Tip: Looking for answers? Try searching our database.

Design Time support for custom columns in DataGridView (VS 2005)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
robrich - 09 Aug 2005 18:55 GMT
In VS 2003 using the standard DataGrid, I was able to get Deisgn Time support
for custom columns by creating a custom ColumnStylesCollectionEditor and
defining my own list like so:

public class MyDataGrid : DataGrid {

    [Editor(typeof(MyTableStylesCollectionEditor), typeof(UITypeEditor))]
    public new GridTableStylesCollection TableStyles {
        get {return base.TableStyles;}
    }
}

public class MyTableStyle : DataGridTableStyle {

    public MyTableStyle() {
    }

    [Editor(typeof(MyColumnStylesCollectionEditor), typeof(UITypeEditor))]
    public new GridColumnStylesCollection GridColumnStyles {
        get {return base.GridColumnStyles;}
    }

}

public class MyTableStylesCollectionEditor : CollectionEditor {

    public MyTableStylesCollectionEditor(Type type) : base(type) {
    }

    protected override System.Type[] CreateNewItemTypes() {
        return new Type[] {typeof(MyTableStyle)};
    }

}

public class MyColumnStylesCollectionEditor : CollectionEditor {

    public MyColumnStylesCollectionEditor(Type type) : base(type) {
    }

    protected override System.Type[] CreateNewItemTypes() {
        return new Type[] {
                    typeof(DataGridTextBoxColumn),
                    typeof(DataGridBoolColumn),
                    typeof(MyColumn1),
                    typeof(MyColumn2),
                    typeof(MyColumn3)
        };
    }
}

When creating a DataGrid, I add a reference to MyDataGrid, and all is well.  
The design time experience is the same, but the list of column styles is
longer.

How do I create design time support for custom columns in the DataGridView
in 2005?  What CollectionEditor has the list of available types?  What other
classes do I need to override to make this happen?

References:
http://msdn2.microsoft.com/library/ms171618(en-us,vs.80).aspx
Got me a hit list of things to check

http://msdn2.microsoft.com/library/7tas5c80(en-us,vs.80).aspx
This shows how to host my own controls in the DataGridView, referencing the
NOT INCLUDED source code.  Know where the source went?

http://msdn.microsoft.com/newsgroups/managed/default.aspx?dg=microsoft.public.do
tnet.framework.windowsforms.controls&tid=f35d4224-b1af-473e-b8f1-ba99ade9a822

A reference on this group to overriding the initialization of a column to
set the ComboBoxStyle to DropDown instead of DropDownList

robrich
"Jeffrey Tan[MSFT]" - 10 Aug 2005 07:33 GMT
Hi robrich,

Thanks for your post.

Yes, the sample code for the article "Host Controls in Windows Forms
DataGridView Cells" is missed in that link. Fortunately, in
forums.microsoft.com, a Microsoft PM has posted up the sample code, you may
get it from the link:
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=66954

For the design-time support issue, yes, Whidbey has complete different
editor for DataGridView. If we use Reflector to view DataGridView.Columns
property, we can see that its default editor is:
System.Windows.Forms.Design.DataGridViewColumnCollectionEditor.

Then, in "public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)" of
DataGridViewColumnCollectionEditor class, it just constructs a
DataGridViewColumnCollectionDialog for editing the columns collection.

In DataGridViewColumnCollectionDialog.addButton_Click method(which is
triggered when we clicked the add button on the editor form), designer will
popup another form to add new column, that is: DataGridViewAddColumnDialog

Then, in DataGridViewAddColumnDialog constructor, we should find
PopulateColumnTypesCombo() method calling to be interesting. Yes, actually,
it takes the responsibility for populating the column type combobox.

At last, we see that in PopulateColumnTypesCombo() method, the code below
get a collection of types, which is used for filling the combobox:
service1.GetTypes(DataGridViewAddColumnDialog.dataGridViewColumnType,
false));  //service1 is of type: ITypeDiscoveryService

If we look in the Whidbey MSDN document below for
ITypeDiscoveryService.GetTypes() method:
http://msdn2.microsoft.com/library/ssy78ba2(en-us,vs.80).aspx
We see that:
"If baseType is null, all types are returned. Otherwise, only types derived
from the specified base type are returned. If excludeGlobalTypes is false,
types from all referenced assemblies are checked. Otherwise, only types
from non-Global Assembly Cache (GAC) referenced assemblies are checked."

So, if we add our customized column into the current project, VS.net
design-time will successfully query this and display our column type in the
combobox for user to select(because our customized column is a child type
of DataGridViewAddColumnDialog.dataGridViewColumnType).

I have tried the sample code in
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=66954, the
CalendarColumn will appear in the combobox successfully.

Hope this helps.
============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

robrich - 12 Aug 2005 17:31 GMT
Jeffrey,

Yes, your comments did help very much.  I've stepped in some bad code, and
have to wipe my shoes before I'll be able to get back to this to try it out.  
It looks mega-cool though.

Can I add a reference to a class library (.dll) full of columns not in the
GAC and use them in the designer as well?

robrich
"Jeffrey Tan[MSFT]" - 15 Aug 2005 02:58 GMT
Hi robrich,

I am glad my reply can help you.

For your further question, I think you may have some misunderstanding in my
last reply.
As I stated in last reply, VS.net designer query the design-time columns
with the statement below:
service1.GetTypes(DataGridViewAddColumnDialog.dataGridViewColumnType,
false));  //service1 is of type: ITypeDiscoveryService

From MSDN for ITypeDiscoveryService.GetTypes, we can see that:
"If excludeGlobalTypes is false, types from all referenced assemblies are
checked. Otherwise, only types from non-Global Assembly Cache (GAC)
referenced assemblies are checked."

In our situation, "false" is passed as "excludeGlobalTypes" parameter to
ITypeDiscoveryService.GetTypes method. This indicated that VS.net designer
will not check the GAC, while it will only get all the referenced
assemblies. So the answer to your question is: Yes. We can place all the
custom defined column styles in an assembly, then in the DataGridView
project, we can just add this assembly in the project as reference. All
will be OK now.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 22 Aug 2005 09:31 GMT
Hi robrich,

Does my reply resolve your problem? If you still have any concern, please
feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 12 Aug 2005 06:56 GMT
Hi robrich,

Does my reply make sense to you? If you have any concern, please feel free
to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.