private void button1_Click(object sender, System.EventArgs e)
{
if (this.checkedListBox1.CheckedItems.Count > 0)
{
this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}
}
for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
{
this.checkedListBox1.SetItemChecked ( i , false) ;
}
}
和下面的为什么不一样. private void button1_Click(object sender, System.EventArgs e)
{
if (this.checkedListBox1.CheckedItems.Count > 0)
{
this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}
for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
{
this.checkedListBox1.SetItemChecked ( i , false) ;
}
}
}
{
if (this.checkedListBox1.CheckedItems.Count > 0)
{
this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}
}
for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
{
this.checkedListBox1.SetItemChecked ( i , false) ;
}
}
和下面的为什么不一样. private void button1_Click(object sender, System.EventArgs e)
{
if (this.checkedListBox1.CheckedItems.Count > 0)
{
this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}
for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
{
this.checkedListBox1.SetItemChecked ( i , false) ;
}
}
}
解决方案 »
- C# 程序,求高手
- 多线程的一段代码,遇到点儿问题,高手过来看下。
- C#如何获取Word页码
- win7,config配置文件保存时访问被拒绝
- 请问一下 c# 怎么创建SDF文件
- dategrid中显示出了数据 我想取得其中的一个单元格的值 怎么做??
- 窗体错误请指导!!
- 类的构造方法问题?
- #紧急求助!!慕白,孟子过来接帖!C#读取的ASP文件中,截取指定的中文字符?下面有代码和程序
- 再次请教:如何写好这样的多线程程序
- 代码越看越难看,大家在VS.net代码编辑器中都用的什么字体。。。
- 我在VB.NET中生成一个类库,其中一个函数中有collection类型的变量,我要把这个类用在C#中。在C#用什么类型与之对应?
你的第一段代码
if 的条件成立的时候...所执行的代码 为
this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}第二段代码中 所执行的代码为 this.listBox1.Items.Clear() ;
foreach (string items in this.checkedListBox1.CheckedItems)
{
this.listBox1.Items.Add(items.ToString ()) ;
}
for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
{
this.checkedListBox1.SetItemChecked ( i , false) ;
}请注意 你所使用的 { 和 }
this.checkedListBox1.SetItemChecked ( i , false) ;
才會執行
上面至少需用一次判斷this.checkedListBox1.CheckedItems.Count > 0
下面至少需要二次判斷this.checkedListBox1.CheckedItems.Count > 0