Link to home
Start Free TrialLog in
Avatar of mohammadalsayeh
mohammadalsayeh

asked on

unlock data grid view properties in a user control

Hey there

I`m working on this user control using vb.net 2005 that is a form with a data grid view in it

but when I use this user control and try to modify the grid view properties the grid view is locked

and can`t change any of the grid view properties

is there any way that enables the properties of the grid view

thanks in advance
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Aren't you in run mode ?
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mohammadalsayeh
mohammadalsayeh

ASKER

is that the only possible solution for this??

can`t I change the propeties of the grid when I use the user control??
Not so far as I know.  

One feature of OO programming is encapsulation.  A class is only accessible to objects outside the class through the properties, methods and events that the class design expressly sets as Public.  When you put a DataGridView into a UserControl the class is the UserControl.  The DataGridView becomes "encapsulated" in the UserControl.  That means that the UserControl can change the properties of the DataGridView, but none of the properties, methods or events of the DataGridView is accessible to anything outside the UserControl.  

As the outside world is dealing with the UserControl, THAT can be designed to accept "instructions" that it will "pass on" to the encapsulated DataGridView.  I gave you a general example - of actually getting hold of the datagridview - in my last post.  An example of the use of a property of the user control that would achive the same thing would be code like this

    Public Property dgvBackgroundColor() As System.Drawing.Color
        Get
            Return myDataGridView.BackgroundColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            myDataGridView.BackgroundColor = value
        End Set
    End Property

in the UserControl and like this

        myUserControl.dgvBackgroundColor = Color.Blue

in the form.

But I don't think you can both encapsulate the DataGridView in a UserControl and then also expect to change its properties as you would if it were a free-standing control.

Roger
Perhaps I should have added one point.  If you want to make the property from the example above visible in the Properties Pane for the UserControl you need to add Browsable to the declaration.  Like this

    <System.ComponentModel.Browsable(True)> _
Public Property dgvBackgroundColor() As System.Drawing.Color

Roger