I have a customer control and a datagridview control in one of my windows form. What do I want is to and a property in my customer control and refer to the datagridview, just like refer a contextmenu to a datagridview. then in my customer control I want to access that datagridview. my code is like below, but it doesn't work:
<code>
class windowform
Me.UsCtrl.uDataGridView = Me.myDataGridViewend class
class UsCtrl
private v_rdv as windows.Forms.DataGridView
Public Property uDataGridView () As windows.Forms.DataGridView
Get
Return v_rdv End Get Set(ByVal value As windows.Forms.DataGridView )v_rdv= value
End Set End Property</code>
Please help me to figure it out. Thanks in advance.

How to pass reference of control to a property?
Grant Holliday
public class form1
dim myuc as new uctrls
myuc.uFlexGrid=_flexGrid
end class
Public Class uctrls
Private v_sFilter As String
Private v_rfg As C1.Win.C1FlexGrid.C1FlexGrid
Public Property uFlexGrid() As C1.Win.C1FlexGrid.C1FlexGrid
Get
Return v_rfg
End Get
Set(ByVal value As C1.Win.C1FlexGrid.C1FlexGrid)
v_rfg = value
End Set
End Property
Public Sub New()
InitializeComponent()
uGetFlexGrid()
End Sub
Private Function uGetFlexGrid() As Boolean
If v_rfg IsNot Nothing Then
For Each col As C1.Win.C1FlexGrid.Column In v_rfg.Cols
If col.Caption <> "" Then
Console.WriteLine(col.Caption)
End If
Next
End If
End Function
End Class
Any good idea, pls
antidotcb
The code seems fine, works at the design time too... Could you post some more details about the problem
Andrej
MatMc
Yes, you're right, this wouldn't work.... I'd say you have two options... Add a new constructor to your control and pass your control as a parameter:
Public Sub New(ByVal grid As C1.Win.C1FlexGrid.C1FlexGrid)
InitializeComponent()
uFlexGrid = Grid
uGetFlexGrid()
End Sub
... and call it like:
Dim myuc as new uctrls(_flexGrid)
or...
remove uGetFlexGrid() call from the constructor (New()) and expose uGetFlexGrid() function as public:
Public Function uGetFlexGrid() As Boolean
...
End Function
... and call it like:
Dim myuc as new uctrls
myuc.uFlexGrid=_flexGrid
myuc.uGetFlexGrid()
Andrej
daniel mark
hafi23
Mohamed Hussein Kotat
I guess you could also call uGetFlexGrid function in the property setter:
Public Property uFlexGrid() As C1.Win.C1FlexGrid.C1FlexGrid
Get
Return v_rfg
End Get
Set(ByVal value As C1.Win.C1FlexGrid.C1FlexGrid)
v_rfg = value
uGetFlexGrid()
End Set
End Property
Andrej