Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes in ListBox 2

Status
Not open for further replies.

sm1it

Programmer
Jun 28, 2004
6
GB
Is it possible to prevent a Tick(Check) appearing in (or likewise disappearing from)the checkbox section of a ListBox control when the User clicks twice on a highlighted line (not a Double Click) ?
 
So, in other words, you don't want user to change your selection from list box, right?

Consider this: just drop list1 set to Style - 1 checkbox
Code:
Option Explicit
Dim i As Integer
Dim blnCheck As Boolean

Private Sub Form_Load()
    For i = 1 To 15
        List1.AddItem "Item " & i
    Next i
    For i = 0 To 15 Step 2
        List1.Selected(i) = True
    Next i
    blnCheck = True
End Sub

Private Sub List1_ItemCheck(Item As Integer)
    If blnCheck = True Then
        List1.Selected(Item) = Not (List1.Selected(Item))
    End If
End Sub

User can not change selected and not selected items.

Is that what you wanted?

---- Andy
 
Thanks for your reply Andy, it's not quite what I was after.

Basically I don't want the user to be able to tick/untick a check-box by clicking on the comment part of the line. i.e. the only way to tick/untick a checkbox is by clicking directly on it.

Hope this is a little clearer.
 
sm,

Try adding this to the code supplied by Andy.

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

blnCheck = (X > 250)

End Sub

HTH Hugh
 
Thanks guys, Andy + Hugh. Just what I wanted.
 
Basically I don't want the user to be able to tick/untick a check-box by clicking on the comment part of the line. i.e. the only way to tick/untick a checkbox is by clicking directly on it.

Just wondering.... WHY?

---- Andy
 
Yeah, if you use a standard control in any way other than the way that it's generally intended you run the risk of making your application counterintuitive, since the average user has used them with their normal behavior. Do also keep in mind that a whole lot more thought went into making the controls the way they are than you're liable to put into changing them. If you are trying, for example, to make sure that the user intended to select the checkbox, then you might devise another way that is in conformance with Microsoft stanards.

HTH

Bob
 
For those of you interested, this is what I was attempting to do. Hope it makes sense, and maybe somebody might suggest an alternative.

I have a listbox on a form, with checkboxes, that lists fixed sentences that the user selects to create case notes. Some of the sentences are complete, others are half written and require the user to finish them with their own text (entered via a textbox under the listbox).

Ticking a checkbox prompts the user to confirm/cancel their selection, likewise unticking a checkbox the user is questioned as to whether they want to remove their choice.

This was fine until the users made a request to be able to edit the endings to those sentences (that they'd previously selected) where they'd had to complete the sentence.

I decided that if they clicked on the 'line' part of the list and it was suitable (i.e. it had a tick, it was 1 of the editable sentences) then an "Edit?" button became available and from there the ability to edit.

However I found that users could accidentally click on the line twice (unticking the checkbox) and trigger the 'Remove Line?' procedure.
 
Thanks for explanation. Fair enough.

Seams to me that you have a lot of message boxes to make sure users get what they want. In out applications we used to have the same, and it made sense while developing the application, but when it came to normal use by people, they have enough of clicking - after any decision they had to conform it. We took all the message boxes out, and left just “Are you sure you want to delete it?” box.

We do use a status bar at the bottom to let the user know that they can only enter numbers, or if the click this button they will do such and such, etc. But no action is required from them, it is just info helping user to do their jobs

---- Andy
 
Aha. Well, you can also just size the check box so that only the box shows, and put the desired caption in a separate label next to it.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top