grid controls of inherited DataGrid class (myDataGridType) are del



I have been using Visual C#.NET to code a large project having many data
adapters, data sets, datagrids, multiple forms with tab pages, each
containing various controls (mostly label, text boxes, check boxes, date
pickers, combo boxes and datagrids). I have been coding alone on this project
for about a year, and I have experienced many problems which have not been
addressed by various SP's, including the recent SP1 to Framework.NET 1.1,
which seemed to be most promising.

In this message, I ask for help in resolving my problems with datagrids of
my derived type being deleted. I have had to create a derived type, since
Microsoft thought it necessary to prevent access to the scroll bar visibility
(which is necessary to counter ANOTHER bug) as well as the inability to
access the function to highlight a grid row. Of course, in order to do this,
I MUST change code in the InitializeComponent section, where the warining
states "do not modify the contents of this method with the code editor". But
since even the MSDN magazine proposes code samples which do exactly that, I
must follow suit and assume that Microsoft has AT LEAST one retard as one of
their programmers.

Unfortunately, the .NET environment randomly decides to throw away my code.
I am forced to frequently exit the environment, so that I can copy the entire
directory structure as a way of limiting my code loss. And no, I will NOT use
SourceSafe, since it introduces even MORE problems than it prevents!

I cannot believe I am the only fool who decided not to purchase 3rd party
data grid software, but if there are any out there who have yet to comit to
using the packaged MS DataGrid, my advice is DON'T! Spend a few hundred bucks
to get something that works reliably. The packaged DataGrid class is only for
the simplest of uses.

The reader may note some bitterness; for that I am sorry, but I have endured
so much pain from this, that I would purposely avoid meeting any MicroSoft
engineers in order to protect myself from a possible homicide charge.

Compounding the problem is the difficulty I face due to the job being
classified: I cannot post code, I have to access a different computer to get
to the Internet, I cannot discuss much detail regarding purpose, and
downloading and installing updates and service packs require third party
intervention and and approval.

I will post questions regarding other issues in other messages, but will
repeat much of the above background information in each.

Help! I have lost SOOOOO much programming time due to these issues, and I
have deadlines to meet!


Nicholas Paldino [.NET/C# MVP]

While I can understand your frustration when you run across bugs in the
framework, you state initially that you are asking for help in resolving
your problems with the datagrid. However, you don't go into specifics about
what the problems are, nor do you give any information about your code and
what you are trying to do.

I've also seen this copied and pasted in another message. Please do not
do this. Your actual problem is being buried under your rhetoric, which is
going to lead to less people reading, and even less people helping you.

That being said, if you can give some more details about your problems
with the DataGrid, then I'm sure there are a few people here who would be
more than willing to help. You mention something about your derived type
being deleted. Do you mean a derived data grid?

As for changing the contents of the InitializeComponent method, if you
place code in there, and lose it, there is nothing that can be said about
that. That code is pretty much not yours, and belongs to the IDE (when you
edit this code in the IDE). It can do what it wishes with that section of


Yes Nicholas, I did cut and paste; and I stated the reason for doing so. Many
of the difficulties I face are related, and I expect that background
information might be helpful: informations such as (1) this is a large
application, (2) many controls on many tab pages on many forms may have
something to do with the problems I have faced, (3) the service pack to
Framework.NET 1.1 did not resolve this or any other problem I mention, (4) I
cannot post code or discuss purpose of the code for reasons stated, (5) I
cannot access the Internet on the developement computer, and (6) every
posited possible solution that involves a download poses its own dificulties.
Now you have stated that providing this background for each message causes
the request for help to be buried under rhetoric, so let me ask you - would
you propose that I NOT provide such information in each message, even though
it may likely be relevent? If so, then you would no doubt offer criticism (as
you already did) that I did not provide enough specifics. That is just great
- deal with everyone you meet with Catch 22's - I really would appreciate
help, but I think I can struggle on without yours.

And you are right that I provided little detail regarding the data grid
problem. Would you propose that I provide extensive detail in the first post?
Of course then, you have already demonstrated your disdain for such detail -
casting it as "rhetoric". There it is again - the Catch 22!

Regarding the InitializeComponent warning. Again your are right! That code
is NOT mine! However, I find it strange that so many MSDN magazine "tips" and
"tricks" cannot be used WITHOUT making such modifcations! So then do you
advise that I not listen to those whom Microsoft has "blessed"? If so, then
what is the point of ANYONE asking for help in this forum?

Granted, some bitterness (I succefully withheld MUCH more!) at MS for
allowing the proposition of modifying code in that magazine against their own
warning otherwise in their own product. That is simply incompetence, and I
believe such bitterness should be overlooked WITHOUT condemnation, but I
could be wrong. Apparently you cannot. Thank you for your demeaning
condemnation for attempting to resolve problems with a MS product without
saintly control of each and every aspect of my anger! Go your own way, and
I'll go mine! May we NEVER meet in person!

Nicholas Paldino [.NET/C# MVP]

You are not giving any relevant details of your project, or your code,
which makes helping you next to impossible. If you can give more detailed
information, it would help tremendously.


Nicholas Paldino said:
You are not giving any relevant details of your project, or your code,
which makes helping you next to impossible. If you can give more detailed
information, it would help tremendously.

The various data grid are first created in design view. I try to make all
initial adjustments in the design view as well. Upon satifaction with the
databinding and overall appearance, I go to where the data grid is defined as
private System.Windows.Forms.DataGrid dgMyDG;
and comment that line out to be replaced as follows:
private MyApp.DgPlus dgMyDG;
Next the first reference as follows:
this.dgMyDG = new System.Windows.Forms.DataGrid( );
is replaced with:
this.dgMyDG = new MyApp.DgPlus( );

Note: Both of the above statements are found within InitilizeComponent, and
I would heed the warning not to modify that code, except such is the only
method proposed by MSDN magazine to access the property
"VertScrollBar.Enabled", which for some reason is inaccessible otherwise. I
do this on the recommendation of an article in MSDN magazine.

The class DgPlus is defined as below, much as proscribed by the magazine.

using System;
namespace MyApp {
public class DgPlus : System.Windows.Forms.DataGrid {
public const int WM_LBUTTONDN = 513; // 0x0201
public const int WM_LBUTTONDN = 514; // 0x0202
public bool codeClick = false;
public DgPlus( ) { }
static extern bool SendMessage(
IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);
static int MakeLong(int LoWord, int HiWord) {
return (HiWord << 16)|(LoWord & 0xffff);
public void ClickRowHeader(int row) {
// get a row to click
System.Drawing.Rectangle rect =- this.GetCellBounds(row, 0);
Int32 lparam = MakeLong(rect.Left - 4, rect.Top + 4);
// inform as to source of this click
codeClick = true;
SendMessage(this.Handle, WM_LBUTTONDN, 0, lparam);
SendMessage(this.Handle, WM_LBUTTONUP, 0, lparam);
// Column ZERO is always a dummy bool column having zero width.
this.CurrentCell = new System.Windows.Forms.DataGridCell(
this.CurrentCell.RowNumber, 0)
codeClick = false;

Hopefully I have typed the above without errors.

My experience seems to indicate that if I never again make a change to the
data grid in Design view, there is not a problem, but if I make a change
which causes the IDE to periodically modify some aspect of the DataGrid
within InitializeComponent(), there is a pretty good chance Visual Studio
will report errors in the Task List window. I can't remember the exact
wording in the Task List window, but it asserts that DgPlus does not exist
within the project. I will try to duplicate this failure on a simple project
and record the exact complaint in a follow up message.

Note: Sometimes I CAN modify the data grid in design view without having
problems, but if it becomes necessary to do so, I always first exit Visual
Studio.NET so that I can copy the entire project off to another disk for
recovery purposes.

Tell me what other specifc information you might need, and I'll try to
provide it.



Upon creation of a test application, the error condition was reproduced when
setting up and redefining the data grid as explained in the previous post.
The error in this case is explainable, but the message is the same as when it
is not.

After I redefined the data grid to my class as:
private MyApp.DgPlus dg1;
then chnaged the first reference to:
this.dg1 = new MyApp.DgPlus( );
I went back to design view without building the application. The data grids
(I had created two) were gone, and the task list window had statements as

Could not find type 'MyApp.DgPlus.' Please make sure that the assembly that
contains this type is referenced. If this type is part of your developement
project, make sure the project has been successfully built'.

The same statement is found for the 2nd data grid, and each of the data grid
references produced statements similar to the following:

The variable 'dg1' is either undeclared or was never assigned.

In this case, the application will still build, and the data grids appear at
runtime, but they do not show up in the designer. Though I could live with
this being the case, other times this has occurred, the assignment to a
particular table style was broken, and at other times all my column
definitions through that table style were lost. The designer would not allow
a method of reattaching the table style, and if I tried, it would complain
that the name I gave it already existed. I could set things right in code
view, but if I did not get everything exactly right, when I went back to
design view it would make the same complaints again, and throw out the code I
had just modified, since it was located in InitializeComponent.

I'll try to discover a method of reliably reproducing the above described
failure, then post that as well, since that is what has cost me so much lost
time. In some cases, I had to choose between reverting to my previously saved
version and losing a days worth of additional coding, or keep the project as
it was coded and spend hours setting all the conditions exactly right for
every datagrid in my solution, only to find that I forgot one thing and it
would throw out all the code changes I just made to fix it.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question