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
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
Aren't you in run mode ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
is that the only possible solution for this??
can`t I change the propeties of the grid when I use the user control??
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.BackgroundC olor
End Get
Set(ByVal value As System.Drawing.Color)
myDataGridView.BackgroundC olor = value
End Set
End Property
in the UserControl and like this
myUserControl.dgvBackgroun dColor = 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
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.BackgroundC
End Get
Set(ByVal value As System.Drawing.Color)
myDataGridView.BackgroundC
End Set
End Property
in the UserControl and like this
myUserControl.dgvBackgroun
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.Bro wsable(Tru e)> _
Public Property dgvBackgroundColor() As System.Drawing.Color
Roger
<System.ComponentModel.Bro
Public Property dgvBackgroundColor() As System.Drawing.Color
Roger