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
  1. Home
  2. General Programming
  3. C#
  4. checklistbox problem

checklistbox problem

Scheduled Pinned Locked Moved C#
helpquestiondatabase
8 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    ASGill
    wrote on last edited by
    #1

    hi.. im trying to populate my checklistbox with a column that im getting from a database. well i get the column and store in a datatable my question how do i populate whats in the datatable into the checklistbox...pls help... :((

    M 1 Reply Last reply
    0
    • A ASGill

      hi.. im trying to populate my checklistbox with a column that im getting from a database. well i get the column and store in a datatable my question how do i populate whats in the datatable into the checklistbox...pls help... :((

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      Set the DataSource propoerty of CheckListBox property to your datatable and its DisplayMember , name of your column. And don't cry , there is always a solution. ;) Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

      A 1 Reply Last reply
      0
      • M Mazdak

        Set the DataSource propoerty of CheckListBox property to your datatable and its DisplayMember , name of your column. And don't cry , there is always a solution. ;) Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

        A Offline
        A Offline
        ASGill
        wrote on last edited by
        #3

        well setting the property is another problem...im using Visual Studio .Net 2003 and it looks like they haved scraped these properties off checklisbox..i wonder why...i tought the more adavanced things got the more easier it got for us...sighhhhh... :(( ... i'll stop once i get this prblem fixed...hehehe

        M 1 Reply Last reply
        0
        • A ASGill

          well setting the property is another problem...im using Visual Studio .Net 2003 and it looks like they haved scraped these properties off checklisbox..i wonder why...i tought the more adavanced things got the more easier it got for us...sighhhhh... :(( ... i'll stop once i get this prblem fixed...hehehe

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          ASGill wrote: it looks like they haved scraped these properties off checklisbox :eek: Although I donn't have VS.NET 2003 but how is this possible? I can understand it. Anyway, can't you set it programiically? Like this:

          checklistbox1.DataSource = mytable;
          checklistbox1.DisplayMember = columnname;

          Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

          A 1 Reply Last reply
          0
          • M Mazdak

            ASGill wrote: it looks like they haved scraped these properties off checklisbox :eek: Although I donn't have VS.NET 2003 but how is this possible? I can understand it. Anyway, can't you set it programiically? Like this:

            checklistbox1.DataSource = mytable;
            checklistbox1.DisplayMember = columnname;

            Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

            A Offline
            A Offline
            ASGill
            wrote on last edited by
            #5

            Hi Mazy...( :eek: yeah i know its kinda shocking.. :) ) anyways... i got the adding part working, its working alrite, but with a flaw...and i have got no clue of what so ever abt why its happennin private void frmPrescription_Load(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT [Med Name] FROM Pharmacy"; oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); oleDbDataAdapter1.Fill(dataSet1); // add items to checkboxlistname. for(int i = 0; i < dataSet1.Tables[0].Rows.Count; i++) { //add items unchecked this.checkedListBoxName.Items.Add(dataSet1.Tables[0].Rows[i][4], false); } } catch (Exception LoadError) { MessageBox.Show(LoadError.ToString()); } finally { oleDbConnection1.Close(); oleDbConnection1.Dispose(); } well when it adds the item, it adds it twice...i.e i have the value "Aspirin" in the column in the table...its s'pose to display it only once but i get 1. Aspirin //numbers represent checkboxes 2. Aspirin 3. Piriton 4. Piriton and so on.....all of the values are added twice..whats wrong... :doh:

            M M 2 Replies Last reply
            0
            • A ASGill

              Hi Mazy...( :eek: yeah i know its kinda shocking.. :) ) anyways... i got the adding part working, its working alrite, but with a flaw...and i have got no clue of what so ever abt why its happennin private void frmPrescription_Load(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT [Med Name] FROM Pharmacy"; oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); oleDbDataAdapter1.Fill(dataSet1); // add items to checkboxlistname. for(int i = 0; i < dataSet1.Tables[0].Rows.Count; i++) { //add items unchecked this.checkedListBoxName.Items.Add(dataSet1.Tables[0].Rows[i][4], false); } } catch (Exception LoadError) { MessageBox.Show(LoadError.ToString()); } finally { oleDbConnection1.Close(); oleDbConnection1.Dispose(); } well when it adds the item, it adds it twice...i.e i have the value "Aspirin" in the column in the table...its s'pose to display it only once but i get 1. Aspirin //numbers represent checkboxes 2. Aspirin 3. Piriton 4. Piriton and so on.....all of the values are added twice..whats wrong... :doh:

              M Offline
              M Offline
              MasudM
              wrote on last edited by
              #6

              Hi I 'm wondering why you : oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); oleDbDataAdapter1.Fill(dataSet1); you olny need to oleDbDataAdapter1.Fill(dataSet1); why did you write oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); first .? bye.

              1 Reply Last reply
              0
              • A ASGill

                Hi Mazy...( :eek: yeah i know its kinda shocking.. :) ) anyways... i got the adding part working, its working alrite, but with a flaw...and i have got no clue of what so ever abt why its happennin private void frmPrescription_Load(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT [Med Name] FROM Pharmacy"; oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); oleDbDataAdapter1.Fill(dataSet1); // add items to checkboxlistname. for(int i = 0; i < dataSet1.Tables[0].Rows.Count; i++) { //add items unchecked this.checkedListBoxName.Items.Add(dataSet1.Tables[0].Rows[i][4], false); } } catch (Exception LoadError) { MessageBox.Show(LoadError.ToString()); } finally { oleDbConnection1.Close(); oleDbConnection1.Dispose(); } well when it adds the item, it adds it twice...i.e i have the value "Aspirin" in the column in the table...its s'pose to display it only once but i get 1. Aspirin //numbers represent checkboxes 2. Aspirin 3. Piriton 4. Piriton and so on.....all of the values are added twice..whats wrong... :doh:

                M Offline
                M Offline
                Mazdak
                wrote on last edited by
                #7

                As Masud said remove oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); line then you call fill method set the DataSource and DisplayMemerb ofCheckListBox as I told you. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

                A 1 Reply Last reply
                0
                • M Mazdak

                  As Masud said remove oleDbDataAdapter1.SelectCommand.ExecuteNonQuery(); line then you call fill method set the DataSource and DisplayMemerb ofCheckListBox as I told you. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

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

                  aight....got it fixed... the oleDbDataAdapter.SelectCommand.ExecuteNonQuery(); was a mistake...the code i posted was an earlier version of it...sorry... thx for the help guys :-D

                  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