Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subclass datagrid control

9 views
Skip to first unread message

Alex Feldman

unread,
Jul 25, 2005, 10:05:13 AM7/25/05
to
I wanted to subclass the DataGrid control to add functionality (that
should have been there in the first place). I have followed
instructions, similar to the ones in the following link that teach how
to subclass controls,

http://support.microsoft.com/default.aspx?scid=kb;en-us;311317

but once I replace the control initialization statements to initialize
to my subclass, the grid disapears from the designer. I guess I can
live with it since If I want to get it back I can uncomment the original
grid initialization if I want to edit the grid from the designer, and
then change the initialization back to a subclass when I'm done, but
isn't there a better way? I tried making the subclass a control
selectable from the toolbox, but it's greyed out when I add it. I
couldn't find a set of good instructions on how to get that to work.

If anyone has good instructions on how to subclass a DataGrid and make
it a selectable control from the toolbox, or just any other suggestion
how I can solve the problem described above I would greatly appreciate it.

Alex Feldman

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 25, 2005, 4:42:26 PM7/25/05
to
The links below should help with understanding custom control development
using the 1.0 version of the CF.
http://www.intelliprog.com/articles/index.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_evtuv/html/etwlkAuthoringCustomControlForSmartDeviceApplications.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_evtuv/html/etconcustomcontroldevelopment.asp

--
Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message
news:tk6Fe.8943$oZ....@newsread2.news.atl.earthlink.net...

Alex Feldman

unread,
Jul 25, 2005, 5:15:22 PM7/25/05
to
Thanks Tim.

All of these examples seem to do a lot of drawing of the control. Do I
have to implement my own OnPaint code, or any other display
functionality? I was thinking of inheriting from the DataGrid control,
so can't I just let the DataGrid do the painting?

Thanks.

Alex

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 25, 2005, 6:01:21 PM7/25/05
to
> Do I have to implement my own OnPaint code,
> or any other display functionality?
No. You should just be able to derive straight from the DataGrid class. The
important thing to note is that you need two assemblies - one for runtime
and one for design-time. The design-time assembly is usually built by hand
(command line, batch file). The assemblies are "linked" through VS using the
RuntimeAssemblyAttribute.

> I was thinking of inheriting from the DataGrid control,
> so can't I just let the DataGrid do the painting?

Yep.

--
Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:KDcFe.9109$oZ....@newsread2.news.atl.earthlink.net...

Alex Feldman

unread,
Jul 26, 2005, 1:16:17 PM7/26/05
to
Thanks Tim.

I am trying to run the batch file to do the build, and I get the
following errors:

========Batch file=========
vbc /netcf /define:NETCFDESIGNTIME /target:library
/out:design.DataGridPlus.dll DataGridPlus.vb /r:"C:\Program
Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK
\v1.0.5000\Windows CE\Designer\System.CF.Design.dll" /r:"C:\Program
Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Windows.Forms.dll" /r:"C:\Program Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Drawing.dll" /r:System.Windows.Forms.dll
/r:System.Drawing.dll /r:System.dll /r:System.XML.dll /r:
System.Web.Services.dll /r:System.Data.dll
========Batch file=========

Microsoft (R) Visual Basic .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.

vbc : error BC30249: Project-level conditional compilation constant
'NETCFDESIGN
TIME' is not valid: '=' expected.
C:\[ProgramPath]\DataGridPlus.vb(34) : error BC30284: sub 'OnMouseDown'
cannot be declared 'Overrides' because it does not override a sub in a
base class.

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
~~~~~~~~~~~

C:\[ProgramPath]\DataGridPlus.vb(34) : warning BC40003: sub
'OnMouseDown' shadows an overloadable member declared in the base class
'DataGrid'. If you want to overload the base method, this method must
be declared 'Overloads'.

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
~~~~~~~~~~~

C:\Data\Bartech
Software\PocketBartLite\PBLiteSolution\CustomControls\DataGridPl
us.vb(34) : error BC30560: 'MouseEventArgs' is ambiguous in the
namespace 'Syste
m.Windows.Forms'.

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

(--OTHER ERRORS FOLLOW, BUT THEY'RE THE SAME AS ABOVE)
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~


What am I doing wrong? I tried doing just an override overload, or just
an overload, but still got errors. The override worked just fine when I
was subclassing within my application. Also, I based the .BAT file on
the C# compiler example, so I modified it the best I can, but I'm not
sure that it's 100% right.

Thanks for the help.

Alex

Alex Feldman

unread,
Jul 26, 2005, 2:42:36 PM7/26/05
to
Thanks Tim!

When you say "restructure your code", do you mean just the custom
control code? If it's just the custom control code that needs to be in
C# while the application using the control can be in VB.NET that's not a
problem for me. Rewriting the application that would use this control
to be in C# however is not an option.

Thanks again!

Alex

Tim Wilson wrote:
> Building a design-time control is currently only supported using the C#
> compiler in version 1.0 of the CF. I believe that the general idea is that
> the VB compiler throws errors/warnings that can't be suppressed during a
> "design-time build", whereas the C# compiler can suppress these
> errors/warnings. The alternative at this point is to not have a design-time
> version of your control, instead create it manually through code, or you'll
> need to restructure your code in the C# language.
>

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 26, 2005, 2:29:36 PM7/26/05
to
Building a design-time control is currently only supported using the C#
compiler in version 1.0 of the CF. I believe that the general idea is that
the VB compiler throws errors/warnings that can't be suppressed during a
"design-time build", whereas the C# compiler can suppress these
errors/warnings. The alternative at this point is to not have a design-time
version of your control, instead create it manually through code, or you'll
need to restructure your code in the C# language.

--

Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:BduFe.9388$oZ....@newsread2.news.atl.earthlink.net...

Alex Feldman

unread,
Jul 26, 2005, 4:32:25 PM7/26/05
to
Well, I've got the code in C#, and it compiled in the DOS prompt OK, and
I've got the 2 dll files that I copy to their appropriate locations.
However, when I add the customized DataGrid control to the toolbox it is
greyed out. I've checked the references in both projects (custom
control and user of control), and there doesn't seem to be anything
missing (as far as I can tell anyway). Do you have any suggestions? I
think I'm almost there!

Thanks.

Alex4

Tim Wilson wrote:
>>When you say "restructure your code", do you
>>mean just the custom control code?
>

> Yes.


>
>
>>If it's just the custom control code that needs to
>>be in C# while the application using the control can
>>be in VB.NET that's not a problem for me. Rewriting
>>the application that would use this control to be in C#
>>however is not an option.
>

> Only the custom control would need to be rewritten in C#. You can consume
> this control, even through the designer, with a VB.Net project.
>

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 26, 2005, 5:13:35 PM7/26/05
to
A couple things that come to mind... Are you sure that you properly included
the RuntimeAssemblyAttribute? Are you sure that you properly built the
design-time assembly against the CF designer assemblies and the desktop
assemblies? When you added the control to the ToolBox did you browse to the
design-time assembly?

--
Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:t5xFe.9451$oZ....@newsread2.news.atl.earthlink.net...

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 26, 2005, 3:19:02 PM7/26/05
to
> When you say "restructure your code", do you
> mean just the custom control code?
Yes.

> If it's just the custom control code that needs to
> be in C# while the application using the control can
> be in VB.NET that's not a problem for me. Rewriting
> the application that would use this control to be in C#
> however is not an option.

Only the custom control would need to be rewritten in C#. You can consume
this control, even through the designer, with a VB.Net project.

--

Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:wuvFe.9419$oZ....@newsread2.news.atl.earthlink.net...

Sergey Bogdanov

unread,
Jul 27, 2005, 9:55:25 AM7/27/05
to

Alex Feldman

unread,
Jul 27, 2005, 10:07:53 AM7/27/05
to
Thanks Sergey,

I've looked at your thread before. I was actually missing the

/r:"C:\Program Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Windows.Forms.DataGrid.DLL"

line in my .bat file. I just added it and recompiled. The control is
still greyed out :-(

Alex

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 27, 2005, 10:42:34 AM7/27/05
to
I added your source (AssemblyInfo.cs and DataGridPlus.cs) to a new class
library project and built it to produce the CustomControls.dll runtime
output. Then I modified the batch file as shown below...

csc /noconfig /define:NETCFDESIGNTIME /target:library
/out:design.CustomControls.dll AssemblyInfo.cs DataGridPlus.cs


/r:"C:\Program Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Design.dll" /r:"C:\Program Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Windows.Forms.dll" /r:"C:\Program Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Windows.Forms.DataGrid.dll" /r:"C:\Program


Files\Microsoft
Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Drawing.dll" /r:System.Windows.Forms.dll

/r:System.Drawing.dll /r:System.dll /nowarn:1595

copy /y design.CustomControls.dll "C:\Program Files\Microsoft


Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer"

copy /y bin\debug\CustomControls.dll "C:\Program Files\Microsoft


Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE"

Then I added the control to the ToolBox by navigating to the design-time
version (design.CustomControls.dll). The control appears in the ToolBox as
it should, I could drag and drop it onto the Form, and the associated
runtime assembly was automatically added as a reference.

--
Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:D7MFe.17817$aY6....@newsread1.news.atl.earthlink.net...
> Hi Tim,
>
> I think I did all that correctly. I'm attaching my project for the custom
> control to this post. You will find the .bat file in root directory that
> builds the design time dll and then copies the dlls to the necessary
> destinations. I would then try to add the control by selecting the
> design.CustomControls.dll file in the copied location.
> The RuntimeAssemblyAttribute is set in the AssemblyInfo file, as I've seen
> someone do in this forum before.
>
> On a side note, I have this project as part of my solution that also
> includes the project for my application that uses this custom control. I
> really don't think it should matter since the dlls are copied and are
> autonomous from the Visual Studio IDE. Just wanted to mention that.
>
> Thanks for your help.
>
> Alex
>
>
> "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
> news:%23kvX2ai...@tk2msftngp13.phx.gbl...

Sergey Bogdanov

unread,
Jul 27, 2005, 10:44:42 AM7/27/05
to
You have missed AssemblyInfo.cs and System.CF.Drawing.dll. Try this command:

csc /noconfig /define:NETCFDESIGNTIME /target:library
/out:design.CustomControls.dll DataGridPlus.cs AssemblyInfo.cs

/r:"C:\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Design.dll" /r:"C:\Program Files\Microsoft Visual

Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Windows.Forms.dll" /r:"C:\Program Files\Microsoft

Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Drawing.dll" /r:"C:\Program Files\Microsoft Visual

Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows

CE\Designer\System.CF.Windows.Forms.DataGrid.DLL" /r:System.Drawing.dll
/r:System.Windows.Forms.dll /r:System.dll /r:System.XML.dll
/r:System.Data.dll /nowarn:1595


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


Alex Feldman wrote:
> I'm attaching the revised project, with the .bat file modified.
> Alex


>
>
> "Alex Feldman" <alex-f...@hotmail.com> wrote in message

> news:ZyMFe.9912$oZ....@newsread2.news.atl.earthlink.net...

Alex Feldman

unread,
Jul 27, 2005, 11:21:01 AM7/27/05
to
Well, to kind of answer my own question, I can add the new grid to the
form, and delete the old one. Then I rename the new grid to the old
one's name. Lastly, I can add the
Me.dgGridName.TableStyles.Add(Me.DataGridTableStyle1) to the
"DataGridName" section of InitializeComponent method, and all the column
configuration is saved that way. If anyone has a better way I'd love to
hear it :-)

Alex

Alex Feldman wrote:
> ALRIGHT!
>
> Got it working. I made a few small changes to the .bat file. I also had a
> reference to the namespace containing the custom control in my application,
> and I removed that as well. After recompiling that time everything
> worked!. I am attaching the project to this email so that if anyone wants
> to use it in the future they have a quick project to start from. I believe
> that many different custom controls can be added to this project and
> compiled with the .bat file (although I haven't tested it out).
>
> Quick question though....what's the easiest way to subsitute my new custom
> grid in place of the existing grids on my form? When I try to substitude
> the declaration and initialization from the standard to my custom one in
> code the control dissapeared from the designer. I can add a new one and
> reconfigure it the way I did the originals, but is there a way to
> substitute?
>
> Thanks for the help Tim,
> Spasibo Sergey.
>
> Alex


>
> "Alex Feldman" <alex-f...@hotmail.com> wrote in message

> news:TMMFe.9913$oZ....@newsread2.news.atl.earthlink.net...


>
>>I'm attaching the revised project, with the .bat file modified.
>>Alex
>>
>>

>>"Alex Feldman" <alex-f...@hotmail.com> wrote in message

>>news:ZyMFe.9912$oZ....@newsread2.news.atl.earthlink.net...

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 27, 2005, 11:21:20 AM7/27/05
to
Once the reference to your CustomControls.dll has been added to the project,
you can then just search and replace "System.Windows.Forms.DataGrid" with
the fully qualified name of your custom DataGrid "<namespace>.<classname>".
That should allow you to do substitution.

--
Tim Wilson
.Net Compact Framework MVP

"Alex Feldman" <alex-f...@hotmail.com> wrote in message

news:NbNFe.9925$oZ....@newsread2.news.atl.earthlink.net...


> ALRIGHT!
>
> Got it working. I made a few small changes to the .bat file. I also had
a
> reference to the namespace containing the custom control in my
application,
> and I removed that as well. After recompiling that time everything
> worked!. I am attaching the project to this email so that if anyone wants
> to use it in the future they have a quick project to start from. I
believe
> that many different custom controls can be added to this project and
> compiled with the .bat file (although I haven't tested it out).
>
> Quick question though....what's the easiest way to subsitute my new custom
> grid in place of the existing grids on my form? When I try to substitude
> the declaration and initialization from the standard to my custom one in
> code the control dissapeared from the designer. I can add a new one and
> reconfigure it the way I did the originals, but is there a way to
> substitute?
>
> Thanks for the help Tim,
> Spasibo Sergey.
>
> Alex
>

> "Alex Feldman" <alex-f...@hotmail.com> wrote in message

> news:TMMFe.9913$oZ....@newsread2.news.atl.earthlink.net...
> > I'm attaching the revised project, with the .bat file modified.
> > Alex
> >
> >

> > "Alex Feldman" <alex-f...@hotmail.com> wrote in message

> > news:ZyMFe.9912$oZ....@newsread2.news.atl.earthlink.net...

Tim Wilson UNDERSCORE AT PERIOD

unread,
Jul 27, 2005, 11:30:46 AM7/27/05
to
I should clarify that you should probably allow the CustomControls.dll
(runtime) reference to be added automatically by dragging and dropping an
instance of your custom DataGrid from the ToolBox. That way the appropriate
design-time reference will be added to the project file as well. Then you
can just delete that instance that you just added. So you're basically using
VS to set up the references for you by dropping your control onto the form
through the designer. After that then you can go into the source and search
and replace like I mentioned. Since you're deriving from the DataGrid,
everything that you have done through the designer against the CF DataGrid
will be able to be done against your custom DataGrid.

--
Tim Wilson
.Net Compact Framework MVP

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:%23a8Qq6r...@TK2MSFTNGP12.phx.gbl...

0 new messages