HI GM
I was created Dynamic Checkboxes and OPtionbuttons.
My task is , when i check the selected Checkbox that corresponding Option buttons should be Enabled...
Can u help me on the code part..
Thanks
Printable View
HI GM
I was created Dynamic Checkboxes and OPtionbuttons.
My task is , when i check the selected Checkbox that corresponding Option buttons should be Enabled...
Can u help me on the code part..
Thanks
HI
I know the coding part how to declare but the problem is where i have to declare?? in the below i am using this code...
For i = 1 To rcount
If Me.Controls("Checkbox" & i).Value = 1 Then
Me.Controls("Option1" & i).Enabled = True
Me.Controls("Option2" & i).Enabled = True
Else
Me.Controls("Option1" & i).Enabled = False
Me.Controls("Option2" & i).Enabled = False
End if
Next i
In general this code we need to declare on click event in dynamic checkbox..
but how to access the the click event in dynamic checkboxes??
i created code for Dynamic Checkboxes.. like this
Set MyCheck = frmMultyTabs.Controls.Add("vb.CheckBox", "Checkbox" & (annexpchk), myframe)
With MyCheck
.Caption = rsDateDiff.Fields(0).Value & "-" & rsDateDiff.Fields(1).Value
.Top = 200
.Left = 100
.Font = arial
.FontBold = True
.FontSize = 10
.BackColor = &HFFC0C0
.Width = 4500
.Height = 400
.Visible = True
End With
Thanks
Is rcount declared? What about i?
Code:For i = 1 AS Integer To rcount
Yes i was declared. It is working.. but my question is how to access the dynamic checkbox?? I need work on Dynamic Checkbox click evevt method....
Thanks for given Replay
Hi,
Check this :
http://social.msdn.microsoft.com/For...3-215deb7e8a17
Modify Accordingly..
Regards
Veena
Ok Thank u Veena i will see
See this link by Merri
http://www.vbforums.com/showpost.php...44&postcount=4
I am sorry to say that still i am not getting the code for how to create Dynamic controls with Events??
I need to create Dynamic CheckBoxes in the Dynamic Frames....
B`se i want to use Dynamic Checkboxes with Click Events some where in the Programe.
Sample code for create Dynamic Frame , within a frame one Checkbox(It is also Dynamic) with Evets..
Thanks
(Plz help for Code)
Hi,
Add A ClassModule to your project and name it "clsCheck"..
write this code in the Class module:
... You can write your Event procedure in this class module accordingly...vb Code:
Option Explicit Private WithEvents chkBox As CheckBox Public Property Set Check_Box(Check_Box As CheckBox) Set chkBox = Check_Box End Property Private Sub chkBox_GotFocus() chkBox.BackColor = vbBlue End Sub Private Sub chkBox_LostFocus() chkBox.BackColor = vbWhite End Sub
And In your Form Decalre these Variables FormLevel...
And the code in FormLoad to add Frame..
vb Code:
Option Explicit Dim i As Integer Dim MyChkColl As Collection ' Private Sub Form_Load() i = 0 Me.Controls.Add "vb.Frame", "Frame1" Me.Controls("Frame1").Visible = True Me.Controls("Frame1").Width = Me.Width - 500 Me.Controls("Frame1").Height = Me.Height - 500 ' Set MyChkColl = New Collection ' End Sub
To Add a Check Box, write this code:
vb Code:
Dim ctl As CheckBox Me.Controls.Add "vb.CheckBox", "Checkbox" & i Set ctl = Me.Controls("Checkbox" & i) With ctl .Visible = True .Left = 0 .Top = 0 If i > 0 Then .Top = Me.Controls("CheckBox" & (i - 1)).Top + 300 End If End With Set ctl.Container = Me.Controls("Frame1") ' Dim tChk As New clsCheck Set tChk.Check_Box = ctl MyChkColl.Add tChk, ctl.Name ' i = i + 1
Now all the Events in the Classmodule are hooked to your Dynamically created Checkboxes...
Regards
Veena
Thank u Veena Thank u so much....
It is Working.
In the above code i added two optionbuttons extra and i run the program it`s working.. But now my task is when i check the checkbox corresponding optionbutton should be Enabled otherwise it is Disabled.
and i am sending code which i was developed both Class and Form as below.
Class:
Option Explicit
Private WithEvents chkBox As CheckBox
Public Property Set Check_Box(Check_Box As CheckBox)
Set chkBox = Check_Box
End Property
Private Sub chkBox_GotFocus()
chkBox.BackColor = vbBlue
End Sub
Private Sub chkBox_LostFocus()
chkBox.BackColor = vbWhite
End Sub
Form:
Option Explicit
Dim i As Integer
Dim MyChkColl As Collection
Dim ctl As CheckBox
Dim Opt1 As OptionButton
Dim Opt2 As OptionButton
Private Sub Form_Load()
For i = 1 To 5
Me.Controls.Add "vb.Frame", "Frame1" & i
Me.Controls("Frame1" & i).Visible = True
Me.Controls("Frame1" & i).Top = 1400 * (i) + 400
Me.Controls("Frame1" & i).Width = 5000
Me.Controls("Frame1" & i).Height = 1400
Me.Controls("Frame1" & i).Left = 10000
'
Set MyChkColl = New Collection
'
Me.Controls.Add "vb.CheckBox", "Checkbox" & i
Set ctl = Me.Controls("Checkbox" & i)
Set ctl.Container = Me.Controls("Frame1" & i)
With ctl
.Visible = True
.Left = 100
.Top = 200
.Width = 4600
.Height = 400
End With
Me.Controls.Add "vb.OptionButton", "MyOptionbutton1" & i
Set Opt1 = Me.Controls("MyOptionbutton1" & i)
Set Opt1.Container = Me.Controls("Frame1" & i)
With Opt1
.Visible = True
.Top = 600
.Left = 100
.Width = 4600
.Height = 255
.Caption = "Current Year" & i
.Enabled = False
End With
Me.Controls.Add "vb.OptionButton", "MyOptionbutton2" & i
Set Opt2 = Me.Controls("MyOptionbutton2" & i)
Set Opt2.Container = Me.Controls("Frame1" & i)
With Opt2
.Visible = True
.Top = 900
.Left = 100
.Width = 4600
.Height = 195
.Caption = "Last Year" & i
.Enabled = False
End With
'
Dim tChk As New clsCheck
Set tChk.Check_Box = ctl
MyChkColl.Add tChk, ctl.Name
'
Next i
End Sub
So, now how can i write code for checkbox click event??
When i Click Checkbox(i) then OPtionbutton1(i) and OPtionbutton2(i) should Enable else Disable..
Thanks
And one more thing is i am not undersatnd this below code .... For wht perpose it will use??
Dim tChk As New clsCheck
Set tChk.Check_Box = ctl
MyChkColl.Add tChk, ctl.Name
Thanks
Hi,
MyChkColl is the collection...
Add OptionButton Control to the ClassModule and write the code In Click event of the optionbutton accordingly...
Regards
Veena
Veena is there necessary to declare optionbuttons withEvents in the Class??
Thanks
Hi,
Why not Create Control Arrays...? that way your code becomes very simple and easily manageable...
and you can write all the code at design time...
Regards
Veena
Hi
Actually i am working on Dynamic controls and i have no idea even how to create Dynamic controls by using Arrays... and i hope this(By using above code) way we will get output...
Arrays means By using Index Property we can generate the controls right??
Hi,
Yes...
Place a CheckBox and make it's Index =0, Visible =False
To Load another use this code..
vb Code:
i=i+1 Load Check1(i) Check1(i).Caption = Check1 & "i" Check1(i).Visible = True
Regards
Veena
I was worked Index Method , It will work , I know.
But the Problem is i am learning VB.NET08 .
In a VB.NET i want to work Dynamic Controls by using WithEvents Method,so i am trying to get WithEvents Method in vb6.If Once i get in vb6 then i will implement on vb.net.Upto now i didn`t tried Index Method in vb08.
Ok Thanks for given Replay thank u so much.