Results 1 to 18 of 18

Thread: Checkboxs and OPtion buttons Dynamically

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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

  3. #3
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Checkboxs and OPtion buttons Dynamically

    Is rcount declared? What about i?
    Code:
    For i = 1 AS Integer To rcount

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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

  5. #5
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: Checkboxs and OPtion buttons Dynamically

    Hi,

    Check this :
    http://social.msdn.microsoft.com/For...3-215deb7e8a17

    Modify Accordingly..

    Regards
    Veena

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    Re: Checkboxs and OPtion buttons Dynamically

    Ok Thank u Veena i will see

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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)

  9. #9
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    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:
    1. Option Explicit
    2. Private WithEvents chkBox As CheckBox
    3.  
    4. Public Property Set Check_Box(Check_Box As CheckBox)
    5.     Set chkBox = Check_Box
    6. End Property
    7.  
    8. Private Sub chkBox_GotFocus()
    9.     chkBox.BackColor = vbBlue
    10. End Sub
    11.  
    12. Private Sub chkBox_LostFocus()
    13.     chkBox.BackColor = vbWhite
    14. 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:
    1. Option Explicit
    2. Dim i As Integer
    3. Dim MyChkColl As Collection
    4. '
    5. Private Sub Form_Load()
    6.     i = 0
    7.     Me.Controls.Add "vb.Frame", "Frame1"
    8.     Me.Controls("Frame1").Visible = True
    9.     Me.Controls("Frame1").Width = Me.Width - 500
    10.     Me.Controls("Frame1").Height = Me.Height - 500
    11.     '
    12.     Set MyChkColl = New Collection
    13.     '
    14. End Sub

    To Add a Check Box, write this code:
    vb Code:
    1. Dim ctl As CheckBox
    2.     Me.Controls.Add "vb.CheckBox", "Checkbox" & i
    3.     Set ctl = Me.Controls("Checkbox" & i)
    4.     With ctl
    5.         .Visible = True
    6.         .Left = 0
    7.         .Top = 0
    8.         If i > 0 Then
    9.             .Top = Me.Controls("CheckBox" & (i - 1)).Top + 300
    10.         End If
    11.     End With
    12.     Set ctl.Container = Me.Controls("Frame1")
    13.     '
    14.     Dim tChk As New clsCheck
    15.     Set tChk.Check_Box = ctl
    16.     MyChkColl.Add tChk, ctl.Name
    17.     '
    18.     i = i + 1

    Now all the Events in the Classmodule are hooked to your Dynamically created Checkboxes...

    Regards
    Veena

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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

  12. #12
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    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

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    Re: Checkboxs and OPtion buttons Dynamically

    Veena is there necessary to declare optionbuttons withEvents in the Class??
    Thanks

  14. #14
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    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

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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...

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    Re: Checkboxs and OPtion buttons Dynamically

    Arrays means By using Index Property we can generate the controls right??

  17. #17
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    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:
    1. i=i+1
    2. Load Check1(i)
    3. Check1(i).Caption = Check1 & "i"
    4. Check1(i).Visible = True

    Regards
    Veena

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    229

    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
  •  



Click Here to Expand Forum to Full Width