|
-
Jul 14th, 2010, 11:29 PM
#1
Thread Starter
Addicted Member
Checkboxs and OPtion buttons Dynamically
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
-
Jul 15th, 2010, 12:10 AM
#2
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
-
Jul 15th, 2010, 01:02 AM
#3
Frenzied Member
Re: Checkboxs and OPtion buttons Dynamically
Is rcount declared? What about i?
Code:
For i = 1 AS Integer To rcount
-
Jul 15th, 2010, 01:15 AM
#4
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
-
Jul 15th, 2010, 01:22 AM
#5
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
-
Jul 15th, 2010, 02:55 AM
#6
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
Ok Thank u Veena i will see
-
Jul 15th, 2010, 07:38 AM
#7
Re: Checkboxs and OPtion buttons Dynamically
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jul 19th, 2010, 11:02 PM
#8
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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)
-
Jul 20th, 2010, 12:39 AM
#9
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
Hi,
Add A ClassModule to your project and name it "clsCheck"..
write this code in the Class module:
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
... You can write your Event procedure in this class module accordingly...
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
-
Jul 20th, 2010, 04:11 AM
#10
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
Last edited by malatesh kumar; Jul 20th, 2010 at 04:14 AM.
-
Jul 20th, 2010, 04:41 AM
#11
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
-
Jul 20th, 2010, 04:59 AM
#12
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
Hi,
MyChkColl is the collection...
Add OptionButton Control to the ClassModule and write the code In Click event of the optionbutton accordingly...
Regards
Veena
-
Jul 20th, 2010, 05:08 AM
#13
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
Veena is there necessary to declare optionbuttons withEvents in the Class??
Thanks
-
Jul 20th, 2010, 05:19 AM
#14
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
-
Jul 20th, 2010, 05:31 AM
#15
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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...
-
Jul 20th, 2010, 05:55 AM
#16
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
Arrays means By using Index Property we can generate the controls right??
-
Jul 20th, 2010, 07:11 AM
#17
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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
-
Jul 20th, 2010, 07:26 AM
#18
Thread Starter
Addicted Member
Re: Checkboxs and OPtion buttons Dynamically
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|