Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:49:09+00:00 2026-05-13T07:49:09+00:00

I have a CheckedListBox. I would like to be able to select items when

  • 0

I have a CheckedListBox. I would like to be able to select items when I click on the text but check/uncheck them when I click on the checkbox area on the left. If I set CheckOnClick then the items are checked and unchecked whenever I click, even on the text, so that’s no good. But if I clear CheckOnClick then I have to click twice to check and uncheck.

My first thought is to handle MouseClick or MouseDown events and call IndexFromPoint to find out which row is clicked. Then I would just guess that the checkbox is on the left, from x=position from 0 to, say, ItemRectangle.Height. Depending on the distance from the left, I could select or check/uncheck.

The question is whether there is a better way to determine if the mouse is over the checkbox or over the text. Different styles could have different sized checkboxes and might put them on the left, right, etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:49:09+00:00Added an answer on May 13, 2026 at 7:49 am

    I wrote this and it seems to work, thanks to SLaks. To use this, CheckOnClick must be true and CheckInCheckbox as well. Inherit from CheckedListbox.

    The idea is to figure out where the checkbox is and, if the click is outside of the checkbox, to set the checkstate to its opposite. Later, when the mouseclick is received by the base class, CheckedListbox, it will again change the checkbox state back to what it was.

    A little hacky changing the state back and forth but I couldn’t find any other way to get around the way that CheckedListbox uses SelectedIndex to check/uncheck, which is sort of a hack, too.

    Private MyCheckInCheckbox As Boolean = False
    
    ''' <summary>
    ''' Only change the checkbox value when clicking on the box
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property CheckInCheckbox() As Boolean
        Get
            Return MyCheckInCheckbox
        End Get
        Set(ByVal value As Boolean)
            MyCheckInCheckbox = value
        End Set
    End Property
    
    Private Sub MyCheckedListBox_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        If CheckInCheckbox Then
            Dim border As Integer = 1
            Dim index As Integer = IndexFromPoint(e.Location)
            If index <> ListBox.NoMatches Then
                Dim bounds As Rectangle = Me.GetItemRectangle(index)
                Dim idealCheckSize As Integer
                If Application.RenderWithVisualStyles Then
                    Dim cbState As VisualStyles.CheckBoxState
                    Select Case Me.GetItemCheckState(index)
                        Case CheckState.Checked
                            cbState = VisualStyles.CheckBoxState.CheckedNormal
                        Case CheckState.Indeterminate
                            cbState = VisualStyles.CheckBoxState.MixedNormal
                        Case CheckState.Unchecked
                            cbState = VisualStyles.CheckBoxState.UncheckedNormal
                    End Select
                    Dim g As Graphics = Me.CreateGraphics
                    idealCheckSize = CheckBoxRenderer.GetGlyphSize(g, cbState).Width
                    g.Dispose()
                End If
                Dim centeringFactor As Integer = Math.Max((bounds.Height - idealCheckSize) \ 2, 0)
                If centeringFactor + idealCheckSize > bounds.Height Then
                    centeringFactor = bounds.Height - idealCheckSize
                End If
                Dim box As Rectangle = New Rectangle(bounds.X + border, bounds.Y + centeringFactor, idealCheckSize, idealCheckSize)
                If RightToLeft = Windows.Forms.RightToLeft.Yes Then
                    box.X = bounds.X + bounds.Width - idealCheckSize - border
                End If
                If Not box.Contains(e.Location) Then
                    Me.SelectedIndex = index
                    SetItemChecked(index, Not GetItemChecked(index))
                End If
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 350k
  • Answers 350k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Found! http://www.exampledepot.com/egs/javax.crypto/GetKeyBytes.html Sorry for the inconvenience. May 14, 2026 at 7:04 am
  • Editorial Team
    Editorial Team added an answer For people that are still wondering how to do this,… May 14, 2026 at 7:04 am
  • Editorial Team
    Editorial Team added an answer Yes, easily via the CN parameter: ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Test User:MAILTO:test.user@somewhere.com See also:… May 14, 2026 at 7:04 am

Related Questions

This seems like a fundamentally simple question. I have a WinForms dialog box with
When the checked state of a check box change, I would like to know
I have an abstract user control(baseModule) that has a property that I plan on
I'm using the following code to populate a DataGridView (sqliteAdapter derives from DbDataAdapter): sqliteAdapter.SelectCommand.CommandText
I have a field object and I create a list of fields: class Field

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.