Question on UserControl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dom

    Question on UserControl

    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
    "GridContro l" 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 )

    #2
    Re: Question on UserControl

    On Apr 23, 12:03 pm, Dom <dolivas...@gma il.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
    "GridContro l" 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

    Comment

    Working...