Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Select checkbox from checkbox list through code.

Select checkbox from checkbox list through code.

Scheduled Pinned Locked Moved C#
helpdatabaseregex
8 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sushant Duggal
    wrote on last edited by
    #1

    HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

    Sushant Duggal.

    P A A 5 Replies Last reply
    0
    • S Sushant Duggal

      HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

      Sushant Duggal.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Wouldn't it be something like: chklstGroups.Items[i].Checked=true;? The day has been too long, I've spent frittered too much time on here today, I need sleep. -- modified at 2:25 Thursday 3rd May, 2007 This worked for me: this.checkedListBox1.SetItemChecked(0,true) ;

      1 Reply Last reply
      0
      • S Sushant Duggal

        HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

        Sushant Duggal.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Sushant Duggal wrote:

        chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error

        What sort of error? -- modified at 2:41 Thursday 3rd May, 2007 More information required.

        S 1 Reply Last reply
        0
        • S Sushant Duggal

          HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

          Sushant Duggal.

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          Use debugger to check whether the "if" statement evaluates to true by creating breakpoint at a line inside the if block.

          Regards, Arun Kumar.A

          1 Reply Last reply
          0
          • S Sushant Duggal

            HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

            Sushant Duggal.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I no longer use CheckedListBoxes, I use TreeViews that look like CheckedListBoxes; they're much more advanced.

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Sushant Duggal wrote:

              chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error

              What sort of error? -- modified at 2:41 Thursday 3rd May, 2007 More information required.

              S Offline
              S Offline
              Sushant Duggal
              wrote on last edited by
              #6

              Object reference not set.

              Sushant Duggal.

              P 1 Reply Last reply
              0
              • S Sushant Duggal

                Object reference not set.

                Sushant Duggal.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Then I suppose your chklstGroups hasn't been set. Show more of the code.

                1 Reply Last reply
                0
                • S Sushant Duggal

                  HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,

                  Sushant Duggal.

                  A Offline
                  A Offline
                  AFSEKI
                  wrote on last edited by
                  #8

                  try this: if( (objGroups.Title != null || objGroups.Title != DBNull) && chklstGroups.Items[i].ToString() == objGroups.Title.ToString()) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Hope it helps...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups