Setting the check box in a CheckedListBox in VB.net

Discussion in 'Computer Support' started by Lost, Aug 19, 2006.

  1. Lost

    Lost Guest

    I want to display a list of items in a CheckedListBox and need some,
    but not all, of the items to have the checkbox pre-checked by the
    program.

    In Delphi, this can be done by:

    for i:= 0 to 9 do
    if condition = True then CheckList1.checked:=True;


    I'm trying to do the same thing in VB .Net 2005 Express but can't
    figure out the syntax or even if the action is possible.

    I've tried this:

    For i = 0 To 9
    If condition(i) = True Then CheckedListBox1.CheckedItems(i) = True
    Next i

    Unfortunately, it won't compile. Any ideas?

    --
    This is soc.men, we know better. -- Michael Snyder
     
    Lost, Aug 19, 2006
    #1
    1. Advertising

  2. Lost wrote:
    > I want to display a list of items in a CheckedListBox and need some,
    > but not all, of the items to have the checkbox pre-checked by the
    > program.
    >
    > In Delphi, this can be done by:
    >
    > for i:= 0 to 9 do
    > if condition = True then CheckList1.checked:=True;
    >
    >
    > I'm trying to do the same thing in VB .Net 2005 Express but can't
    > figure out the syntax or even if the action is possible.
    >
    > I've tried this:
    >
    > For i = 0 To 9
    > If condition(i) = True Then CheckedListBox1.CheckedItems(i) = True
    > Next i
    >
    > Unfortunately, it won't compile. Any ideas?


    A VB group?

    --
    Blinky RLU 297263
    Killing all posts from Google Groups
    The Usenet Improvement Project: http://blinkynet.net/comp/uip5.html
     
    Blinky the Shark, Aug 19, 2006
    #2
    1. Advertising

  3. Lost

    why? Guest

    On Sat, 19 Aug 2006 16:17:18 +0100, Lost wrote:

    >I want to display a list of items in a CheckedListBox and need some,
    >but not all, of the items to have the checkbox pre-checked by the
    >program.


    <snip>

    I am not even going to list the possible number of VB guides, developer
    sites, online tutorials it's not worth the effort for something so
    simple.

    >I'm trying to do the same thing in VB .Net 2005 Express but can't
    >figure out the syntax or even if the action is possible.
    >

    <snip>

    Me
     
    why?, Aug 19, 2006
    #3
  4. Lost

    Lost Guest

    why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:

    >
    >On Sat, 19 Aug 2006 16:17:18 +0100, Lost wrote:
    >
    >>I want to display a list of items in a CheckedListBox and need some,
    >>but not all, of the items to have the checkbox pre-checked by the
    >>program.

    >
    ><snip>
    >
    >I am not even going to list the possible number of VB guides, developer
    >sites, online tutorials it's not worth the effort for something so
    >simple.


    Now why didn't I think of looking in my VB books or using google
    before bothering fuckwits like you?

    >>I'm trying to do the same thing in VB .Net 2005 Express but can't
    >>figure out the syntax or even if the action is possible.
    >>

    ><snip>
    >
    >Me



    --
    This is soc.men, we know better. -- Michael Snyder
     
    Lost, Aug 21, 2006
    #4
  5. Lost

    why? Guest

    On Mon, 21 Aug 2006 16:20:08 +0100, Lost wrote:

    >why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >
    >>
    >>On Sat, 19 Aug 2006 16:17:18 +0100, Lost wrote:
    >>
    >>>I want to display a list of items in a CheckedListBox and need some,
    >>>but not all, of the items to have the checkbox pre-checked by the
    >>>program.

    >>
    >><snip>
    >>
    >>I am not even going to list the possible number of VB guides, developer
    >>sites, online tutorials it's not worth the effort for something so
    >>simple.

    >
    >Now why didn't I think of looking in my VB books or using google


    Ah well if you have VB books, why pother asking. Mind you maybe you
    don't have VB 2005 books where a lot of properties changed.

    <snip>

    >
    >>>I'm trying to do the same thing in VB .Net 2005 Express but can't
    >>>figure out the syntax or even if the action is possible.


    Thus you are trying to write programs, not even knowing about the
    methods of the CheckListBox Class.

    http://msdn.microsoft.com

    >>>

    >><snip>
    >>
    >>Me


    Me
     
    why?, Aug 21, 2006
    #5
  6. Lost

    Lost Guest

    why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:

    >
    >On Mon, 21 Aug 2006 16:20:08 +0100, Lost wrote:
    >
    >>why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >>
    >>>
    >>>On Sat, 19 Aug 2006 16:17:18 +0100, Lost wrote:
    >>>
    >>>>I want to display a list of items in a CheckedListBox and need some,
    >>>>but not all, of the items to have the checkbox pre-checked by the
    >>>>program.
    >>>
    >>><snip>
    >>>
    >>>I am not even going to list the possible number of VB guides, developer
    >>>sites, online tutorials it's not worth the effort for something so
    >>>simple.

    >>
    >>Now why didn't I think of looking in my VB books or using google

    >
    >Ah well if you have VB books, why pother asking. Mind you maybe you
    >don't have VB 2005 books where a lot of properties changed.


    Go and play in the traffic, you arsehole. You're either a smug bastard
    who knew the answer but wouldn't share it, or an ignorant pillock
    trying to look wise. My money's on the second.

    >>>>I'm trying to do the same thing in VB .Net 2005 Express but can't
    >>>>figure out the syntax or even if the action is possible.

    >
    >Thus you are trying to write programs, not even knowing about the
    >methods of the CheckListBox Class.


    That's right, I'm converting an old Delphi program to VB.Net. The
    details are hard to find, which is why I asked here.

    >http://msdn.microsoft.com


    First place I looked but it obfuscates.


    For the benefit of any decent people with a similar problem, the
    difficulty arises because a different syntax is used for
    GetItemChecked and SetItemChecked.

    Here's some example code I posted elsewhere by request when I worked
    it out:

    If CheckedListBox1.GetItemChecked(0) = True Then 'is it checked?
    For i = 1 To CheckedListBox1.Items.Count - 1
    CheckedListBox1.SetItemChecked(i, False) 'uncheck item
    Next i
    End If



    --
    This is soc.men, we know better. -- Michael Snyder
     
    Lost, Aug 22, 2006
    #6
  7. Lost

    why? Guest

    On Tue, 22 Aug 2006 22:34:32 +0100, Lost wrote:

    >why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >
    >>
    >>On Mon, 21 Aug 2006 16:20:08 +0100, Lost wrote:
    >>
    >>>why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >>>
    >>>>
    >>>>On Sat, 19 Aug 2006 16:17:18 +0100, Lost wrote:
    >>>>
    >>>>>I want to display a list of items in a CheckedListBox and need some,
    >>>>>but not all, of the items to have the checkbox pre-checked by the
    >>>>>program.
    >>>>
    >>>><snip>
    >>>>
    >>>>I am not even going to list the possible number of VB guides, developer
    >>>>sites, online tutorials it's not worth the effort for something so
    >>>>simple.
    >>>
    >>>Now why didn't I think of looking in my VB books or using google

    >>
    >>Ah well if you have VB books, why pother asking. Mind you maybe you
    >>don't have VB 2005 books where a lot of properties changed.

    >
    >Go and play in the traffic, <snip>
    >who knew the answer but wouldn't share it, or an ignorant pillock
    >trying to look wise. My money's on the second.


    As usual with replies like that you and others are wrong so often, it
    was easy to lookup the online docs.

    <snip>

    >That's right, I'm converting an old Delphi program to VB.Net. The
    >details are hard to find, which is why I asked here.
    >
    >>http://msdn.microsoft.com

    >
    >First place I looked but it obfuscates.


    <snip>

    http://msdn.microsoft.com
    MSDN Home > MSDN Library > .NET Development > .NET Framework SDK >
    ..NET Framework > Reference > Class Library > System.Windows.Forms >
    CheckedListBox Class > Methods

    Example
    [Visual Basic, C#, C++] The following example enumerates the items in
    the CheckedListBox and checks every other item in the list. The example
    demonstrates using the SetItemCheckState and SetItemChecked methods to
    set the check state of an item.

    .....
    CheckedListBox1.SetItemChecked(i, True)
    .....

    Me
     
    why?, Aug 23, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drl711
    Replies:
    0
    Views:
    3,778
    drl711
    Aug 23, 2005
  2. Cowboy \(Gregory A. Beamer\)

    Take MCSD.NET with VB.NET and C#.NET in the same time?

    Cowboy \(Gregory A. Beamer\), Jan 1, 2004, in forum: MCSD
    Replies:
    1
    Views:
    519
    The Fox
    Jan 1, 2004
  3. Tommy Halnet

    w2k box cannot browse w98 box with netbeui

    Tommy Halnet, Jan 2, 2004, in forum: Computer Support
    Replies:
    0
    Views:
    432
    Tommy Halnet
    Jan 2, 2004
  4. VRao

    How to delete list box(text box)

    VRao, Jan 24, 2004, in forum: Computer Support
    Replies:
    3
    Views:
    2,684
    Sultan
    Jan 24, 2004
  5. X Box VS X Box 360

    , Nov 26, 2006, in forum: Computer Support
    Replies:
    3
    Views:
    456
Loading...

Share This Page