inheriting from windows.forms.datagrid

  • Thread starter Thread starter andrei
  • Start date Start date
A

andrei

Hi Group,

I have a class which inherits from Windows.Forms.DataGrid.

Imports System.Drawing
Imports System.Windows.Forms

Public Class MyDataGrid : Inherits System.Windows.Forms.DataGrid
....

Then, inside the class I use a DataGridTableStyle and I add columns derived
from DataGridTextBoxColumn, so I can customize the behaviour.

Next, on a form, I place a regular Datagrid, then I switch to the code and I
replace wherever I find a reference to System.Windows.Forms.DataGrid with
MyDataGrid. So now, the program will use MyDataGrid.
Everything works fine, it compiles, it runs ok. But when I switch back to
the designer, the control
representing the datagrid dissapears.
I've been looking on the internet for articles, and some described the
replacing of a datagrid with a derived datagrid in exactly the same steps.
They were saying that you need to rebuild your projecct in order for your
datagrid not to dissapear.
I've done that, but nothing has changed...

What am I doing wrong ?
Or is it a better way of doing it ?

Any help would be appreciated ! Thanks !

Andrei.
 
Place your MyDataGrid control in the ToolBox. Add it to the form the
same way that you would any other control. Remove the DataGrid from the
form.

The problem is when you drop a control on the form from the Toolbox,
that is remembered by the designer. Every time that you go into the
designer, the code that is in the region marked as "Windows Form
Designer generated code" is regenerated. This is way you are loosing
your changes.

HTH

David
 
Back
Top