471,337 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Question on UserControl

Dom
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
Jun 27 '08 #1
1 1100
On Apr 23, 12:03*pm, Dom <dolivas...@gmail.comwrote:
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
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...perties-i.aspx
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Chris | last post: by
2 posts views Thread by Sascha | last post: by
reply views Thread by Patrick.O.Ige | last post: by
3 posts views Thread by Gary Kahrau | last post: by
12 posts views Thread by Joe | last post: by
2 posts views Thread by Mark Collard | last post: by
7 posts views Thread by John D'oh | last post: by
2 posts views Thread by =?Utf-8?B?TWFyayBDb2xsYXJk?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.