I've created a UserControl comprised of two controls, a DataGridView
and a DateTimePicker. I've done this because one of the columns in
the DataGridView will hold a date, and when the user clicks on the
column, the DateTimePicker will appear.
Now for the problem.
I want the main program to add columns (and other properties) to the
DataGridView control. So I exposed the control, like this (where
dgvMain is the name of the DataGridView control in the UserControl):
public DataGridView GridControl
{
get {return dgvMain;}
}
This is fine. The properties box of the UserControl now has
"GridControl" which opens to the usual properties of a datagridview.
But when I click on "Columns" in the properties box, I get the message
"Object reference not set to an instance of an object." The odd thing
is, I can add columns in code. (Or maybe that's not so odd).
How do I handle this?
Dom
Ignacio Machin ( .NET/ C# MVP ) - 23 Apr 2008 22:52 GMT
> I've created a UserControl comprised of two controls, a DataGridView
> and a DateTimePicker. I've done this because one of the columns in
[quoted text clipped - 22 lines]
>
> Dom
Hi,
Not that's not odd at all :)
you can use it from code with no problem, if you want to use the
designer well, it's a completely different history, you need to
implement at least one interface.
Take a look at MSDN or this article
http://www.eggheadcafe.com/community/aspnet/2/10013886/user-control-properties-i.aspx