Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

CheckedListBox or DataBinding Bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 01 Feb 2005 17:27 GMT
Try this... Run the form. Check a few items in the CheckedListBox. Go to Tab
2 and then back to Tab 1. Uh... what happened? The check marks are
cleared?!!

Any ideas???

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TestCheck
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
 private System.Windows.Forms.TabControl tabControl1;
 private System.Windows.Forms.TabPage tabPage1;
 private System.Windows.Forms.TabPage tabPage2;
 private System.Windows.Forms.CheckedListBox checkedListBox1;
 private System.Windows.Forms.Label label1;
 /// <summary>
 /// Required designer variable.
 /// </summary>
 private System.ComponentModel.Container components = null;

 public Form1()
 {
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent();

  //
  // TODO: Add any constructor code after InitializeComponent call
  //
 }

 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose( bool disposing )
 {
  if( disposing )
  {
   if (components != null)
   {
    components.Dispose();
   }
  }
  base.Dispose( disposing );
 }

 #region Windows Form Designer generated code
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
  this.tabControl1 = new System.Windows.Forms.TabControl();
  this.tabPage1 = new System.Windows.Forms.TabPage();
  this.tabPage2 = new System.Windows.Forms.TabPage();
  this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
  this.label1 = new System.Windows.Forms.Label();
  this.tabControl1.SuspendLayout();
  this.tabPage1.SuspendLayout();
  this.tabPage2.SuspendLayout();
  this.SuspendLayout();
  //
  // tabControl1
  //
  this.tabControl1.Controls.Add(this.tabPage1);
  this.tabControl1.Controls.Add(this.tabPage2);
  this.tabControl1.Location = new System.Drawing.Point(16, 16);
  this.tabControl1.Name = "tabControl1";
  this.tabControl1.SelectedIndex = 0;
  this.tabControl1.Size = new System.Drawing.Size(680, 432);
  this.tabControl1.TabIndex = 0;
  //
  // tabPage1
  //
  this.tabPage1.Controls.Add(this.checkedListBox1);
  this.tabPage1.Location = new System.Drawing.Point(4, 25);
  this.tabPage1.Name = "tabPage1";
  this.tabPage1.Size = new System.Drawing.Size(672, 403);
  this.tabPage1.TabIndex = 0;
  this.tabPage1.Text = "tabPage1";
  //
  // tabPage2
  //
  this.tabPage2.Controls.Add(this.label1);
  this.tabPage2.Location = new System.Drawing.Point(4, 25);
  this.tabPage2.Name = "tabPage2";
  this.tabPage2.Size = new System.Drawing.Size(672, 403);
  this.tabPage2.TabIndex = 1;
  this.tabPage2.Text = "tabPage2";
  //
  // checkedListBox1
  //
  this.checkedListBox1.Location = new System.Drawing.Point(24, 24);
  this.checkedListBox1.Name = "checkedListBox1";
  this.checkedListBox1.Size = new System.Drawing.Size(624, 344);
  this.checkedListBox1.TabIndex = 0;
  //
  // label1
  //
  this.label1.Location = new System.Drawing.Point(248, 168);
  this.label1.Name = "label1";
  this.label1.TabIndex = 0;
  this.label1.Text = "Nothing Here";
  //
  // Form1
  //
  this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
  this.ClientSize = new System.Drawing.Size(712, 464);
  this.Controls.Add(this.tabControl1);
  this.Name = "Form1";
  this.Text = "Form1";
  this.Load += new System.EventHandler(this.Form1_Load);
  this.tabControl1.ResumeLayout(false);
  this.tabPage1.ResumeLayout(false);
  this.tabPage2.ResumeLayout(false);
  this.ResumeLayout(false);

 }
 #endregion

 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 [STAThread]
 static void Main()
 {
  Application.Run(new Form1());
 }

 private void Form1_Load(object sender, System.EventArgs e)
 {
  DataTable dt = new DataTable("BindingTable");
  dt.Columns.Add("Column1");
  dt.Columns.Add("Column2");

  dt.Rows.Add(new object[] {"Hello", "World"});
  dt.Rows.Add(new object[] {"Goodbye", "Cruel World"});
  dt.Rows.Add(new object[] {"Greetings", "Earthling"});

  this.checkedListBox1.DataSource = dt;
  this.checkedListBox1.DisplayMember = "Column2";
  this.checkedListBox1.ValueMember = "Column1";

 }
}
}
Herfried K. Wagner [MVP] - 01 Feb 2005 17:36 GMT
"Jeff" <theemerys@hotmail.com> schrieb:
> Try this... Run the form. Check a few items in the CheckedListBox. Go to
> Tab 2 and then back to Tab 1. Uh... what happened? The check marks are
> cleared?!!

Workaround for disappearing checks in the CheckedListBox control
<URL:http://www.thecodeproject.com/cs/combobox/fixedcheckedlistbox.asp>

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jeff - 01 Feb 2005 17:54 GMT
Thanks Herfried...

There were some solutions there. I took the checkedListBox.BindingContext =
new BindingContext();
approach, but I don't know why that works...

Anyhow Thanks for the help. I really appreciate it!!!

> "Jeff" <theemerys@hotmail.com> schrieb:
>> Try this... Run the form. Check a few items in the CheckedListBox. Go to
[quoted text clipped - 3 lines]
> Workaround for disappearing checks in the CheckedListBox control
> <URL:http://www.thecodeproject.com/cs/combobox/fixedcheckedlistbox.asp>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.