checklistbox problem
-
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... :((
Set the
DataSource
propoerty of CheckListBox property to your datatable and itsDisplayMember
, 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 -
Set the
DataSource
propoerty of CheckListBox property to your datatable and itsDisplayMember
, 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 Hopewell 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
-
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
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
-
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
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: -
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: -
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: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
-
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