Results 1 to 26 of 26

Thread: editing comboboxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    editing comboboxes

    i want the user to only b able to edit after clicking the edit button, so I created a form_keypress sub and if a boolean inEDit is not true then keyAscii is = 0!! it all works fine.

    However I hav alot of comboboxes on the page and at present the user is able to edit the selection!!! how can i write a sub that does the same as form_keypress ie if the user does not click the edit button then the selection of the combobox will not change??

    Thanks in advance
    Last edited by pame1la; Apr 7th, 2005 at 03:53 AM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: editing comboboxes

    Set it to type 2 so that they can't edit it. When they click on it, use a textbox with the value of the combobox. When they press enter, re-write the comboxbox with the updated item. You could even float the textbox ofer the combobox item to have it appear that they are editing the item. I do this with a flexgrid, and the cell appears to change color as I edit it.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    David has a good suggestion, and to take that one step further (if you have the need to do so), you could even lock the textboxes so they can be touched until such time as the Edit button is clicked. Then, you can loop through the textboxes and unlock them.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    Quote Originally Posted by dglienna
    Set it to type 2 so that they can't edit it. When they click on it, use a textbox with the value of the combobox. When they press enter, re-write the comboxbox with the updated item. You could even float the textbox ofer the combobox item to have it appear that they are editing the item. I do this with a flexgrid, and the cell appears to change color as I edit it.

    what do you mean by set it to type 2????

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    On the property page for the combobox, scroll down to Style, and select Style 2 - Dropdown List

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    isn't it easier way to do it... like for the textboxes i have a key-press sub that sets keyascii= 0 if not in edit.....

    is there not sum sort of sub i can write which will make all mouse clicking invalid until it is in edit??????

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    Quote Originally Posted by pame1la
    isn't it easier way to do it... like for the textboxes i have a key-press sub that sets keyascii= 0 if not in edit.....
    Sure. You could use a Boolean that the edit button sets to True. However, this would mean putting
    VB Code:
    1. If blnCanEdit = False Then
    2.      KeyAscii = 0
    3. End If
    in every keypress event of every text box you have.

    Quote Originally Posted by pame1la
    is there not sum sort of sub i can write which will make all mouse clicking invalid until it is in edit??????
    First, you don't want to make all mousing clicking invalid. If you did that no one could click the Edit button to making editing OK.

    If you simply set the Locked property of your textboxes to True, in design, then you could unlock them all by calling a sub from your Edit button that iterates through all your textboxes and unlocks them.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    [QUOTE=Hack]Sure. You could use a Boolean that the edit button sets to True. However, this would mean putting
    VB Code:
    1. If blnCanEdit = False Then
    2.      KeyAscii = 0
    3. End If


    NO I HAVE THAT IN FORM_KEYPRESS SUB.... cant i do sumfing when the user clicks on cmboboxes?? eg. if bInCanEdit = False then cbo1.Locked = True....

    but that would be quite long isn't there anything lik form_mouseclick

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    [QUOTE=pame1la]
    Quote Originally Posted by Hack
    Sure. You could use a Boolean that the edit button sets to True. However, this would mean putting
    VB Code:
    1. If blnCanEdit = False Then
    2.      KeyAscii = 0
    3. End If


    NO I HAVE THAT IN FORM_KEYPRESS SUB.... cant i do sumfing when the user clicks on cmboboxes?? eg. if bInCanEdit = False then cbo1.Locked = True....

    but that would be quite long isn't there anything lik form_mouseclick
    There is a Form_Click() event. You can toggle the Locked property with this.
    VB Code:
    1. Private Sub LockCombos(pblnIsLocked As Boolean)
    2. On Error Resume Next
    3. Dim cCombo As ComboBox
    4. For Each cCombo In Me.Controls
    5.     cCombo.Locked = pblnIsLocked
    6. Next
    7. End Sub
    8.  
    9. 'to turn on editing
    10. LockCombos False
    11. 'to turn off editing
    12. LockCombos True

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    Quote Originally Posted by Hack
    There is a Form_Click() event. You can toggle the Locked property with this.
    VB Code:
    1. Private Sub LockCombos(pblnIsLocked As Boolean)
    2. On Error Resume Next
    3. Dim cCombo As ComboBox
    4. For Each cCombo In Me.Controls
    5.     cCombo.Locked = pblnIsLocked
    6. Next
    7. End Sub
    8.  
    9. 'to turn on editing
    10. LockCombos False
    11. 'to turn off editing
    12. LockCombos True
    It doesnt seem to be doing anything!!! wot i have done is added the above sub and then have wrote LockCombos (True) but it hasnt worked!!!

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: editing comboboxes

    Try to find out if the combobox ia actually being locked...

    VB Code:
    1. Private Sub LockCombos(pblnIsLocked As Boolean)
    2. On Error Resume Next
    3. Dim cCombo As ComboBox
    4. For Each cCombo In Me.Controls
    5.     cCombo.Locked = pblnIsLocked
    6.     msgbox cCombo.Locked
    7. Next
    8. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    Quote Originally Posted by pame1la
    It doesnt seem to be doing anything!!! wot i have done is added the above sub and then have wrote LockCombos (True) but it hasnt worked!!!
    Don't use parenthese. Just say either:

    LockCombos False
    'or
    LockCombos True

  13. #13
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Wink Re: editing comboboxes

    Maybe she used Call LockCombos(True)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    Quote Originally Posted by dee-u
    Maybe she used Call LockCombos(True)

    naaa dont wry i didnt

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    Quote Originally Posted by dee-u
    Maybe she used Call LockCombos(True)
    She could do that if she wished.
    Quote Originally Posted by pame1la
    naaa dont wry i didnt
    Did it work without the parentheses?

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: editing comboboxes

    naaa dont wry i didnt
    Call LockCombos(True) and LockCombos True would just be the same....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    no its still not wrking!!!


    have i understood right: i add the sub

    Private Sub LockCombos(pblnIsLocked As Boolean)
    On Error Resume Next
    Dim cCombo As ComboBox
    For Each cCombo In Me.Controls
    cCombo.Locked = pblnIsLocked

    Next

    End Sub

    in ma code...and after the search option i have added LockCombos True because i want the user not to be able to edit the cmboboxes, den wen they click edit i have LockCombos False......

  18. #18
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: editing comboboxes

    Try to determine if your ComBox is actually being locked in that LockCombos procedure.

    Or perhaps you could post the code where you said it is not working, maybe it is being locked then 'accidentally' unlocked them again....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    theres sumthing wrong with the loop cos it only goes through it 1ce!!!!

  20. #20
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    Quote Originally Posted by pame1la
    no its still not wrking!!!


    have i understood right: i add the sub

    Private Sub LockCombos(pblnIsLocked As Boolean)
    On Error Resume Next
    Dim cCombo As ComboBox
    For Each cCombo In Me.Controls
    cCombo.Locked = pblnIsLocked

    Next

    End Sub

    in ma code...and after the search option i have added LockCombos True because i want the user not to be able to edit the cmboboxes, den wen they click edit i have LockCombos False......
    If I'm understanding what you want to do correctly, you should add LockCombos True in the Form_Load event.

    Then in the click event of your Edit button add LockCombos False.

    Try this...before hitting your Edit button, after the form loads, try to do stuff with the combos. You should not be able to.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    no it still doesnt wrk!!! it doesnt loop through ths sub rite, it sod do it for each combo box rite, eg if i hav 5 comboboxes on the form it should go through the loop 5 times rite????

    it only does 1ce!!!!!!

  22. #22
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    Quote Originally Posted by pame1la
    no it still doesnt wrk!!! it doesnt loop through ths sub rite, it sod do it for each combo box rite, eg if i hav 5 comboboxes on the form it should go through the loop 5 times rite????

    it only does 1ce!!!!!!
    Could you attach your form?

    I just put 5 combo boxes on a test form, ran that sub and locked and unlocked them at will, so I really need to see what you are doing.

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    heres an example:

    Private Sub Combo1_Click()
    txtbox.Text = Combo1.Text
    End Sub

    Private Sub Command1_Click()
    LockCombos False
    End Sub

    Sub Form_Load()
    LockCombos True
    End Sub

    Private Sub LockCombos(pblnIsLocked As Boolean)
    On Error Resume Next
    Dim cCombo As ComboBox
    For Each cCombo In Me.Controls
    cCombo.Locked = pblnIsLocked

    Next
    StatusBar.Panels(1) = "Press Edit button before editing record"
    End Sub

  24. #24
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: editing comboboxes

    You are right Pamela. I took your code, made a form with 5 combos and now I know what you are talking about. Replace the LockCombos sub with this
    VB Code:
    1. Private Sub LockCombos(pblnIsLocked As Boolean)
    2. On Error Resume Next
    3. Dim cCombo As Control
    4. For Each cCombo In Me.Controls
    5.   If TypeOf cCombo Is ComboBox Then
    6.     cCombo.Locked = pblnIsLocked
    7.   End If
    8. Next
    9. End Sub
    It should now work like a champ. Let me know.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    thanks hack it works with the practice thing, now im gona add to my propa question!!!


    can i ask another question.... i have 1 combobox, and when the user edits the combobox a column in a grid is recalculated.... i want it to recalculate that column for ALL rows and not just the row in edit mode....eny ideas????

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    334

    Re: editing comboboxes

    If the comboboxes are locked, i want to add a message on teh status bar, how could i do that????

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