程式查询条件处界面如下:本来是可以用不同的RadioButton来实现的,但是我看到微软VS2003提供了一个控件叫CheckedListBox(它可以绑定数据源进行多选):
□  Condition1
□  Condition2
□  Condition3
□  Condition4
可是我怎么也找不到RadioListButton这样类似CheckedListBox的控件,用RadioButton一个一个去排,当让是可以达到要求的 
○  Condition1
○  Condition2
○  Condition3
○  Condition4
这里我一时心血来潮,于是就想把CheckedListBox改造成我想要的这种“单选”控件组合
经过摸索,用两个事件实现了这个过程!~现介绍过程如下:过程我很难解说的清楚,还是请各位把下面代码搞回去,自己研究吧!呵呵!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace CheckedListBox2RadioListButton
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.CheckedListBox checkedListBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
// 
// checkedListBox1
// 
this.checkedListBox1.Location = new System.Drawing.Point(24, 72);
this.checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(240, 116);
this.checkedListBox1.TabIndex = 0;
this.checkedListBox1.CheckOnClick=true;//当鼠标点击时候状态是否要改变,默认是鼠标点两下才改变状态的,所以这里的设置下
this.checkedListBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.clb_OnMouseDown);
this.checkedListBox1.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.clb_OnItemCheck);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.checkedListBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
for(int iTmp=0;iTmp<5;iTmp++)
{
this.checkedListBox1.Items.Add("Condition"+iTmp.ToString());
}
} /*
 * 这里说一下,这个过程的难点,
 * 1,我们为什么选择这个ItemCheck事件,是因为它的ItemCheckEventArgs类型的参数能够传回当前状态改变时候那个项目的索引
 * 汗,这个逻辑是在是不好叙述成通俗易懂的,希望哪位理解后在翻译给大家!呵呵
 */
int trackNum=0; //使循环变量增加,它控制了整个函数是否会陷入死循环
int index;      //记录鼠标点击的那个项目的索引
bool blnMouseClick=true;//记录鼠标激发ItemCheck事件后的e.Index的值 private void clb_OnItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if(blnMouseClick)
{
index=e.Index;
blnMouseClick=false;
}
for(int i=trackNum;i<this.checkedListBox1.Items.Count;i++)
{
if(i!=index)
{
trackNum++;
this.checkedListBox1.SetItemCheckState(i,CheckState.Unchecked); //这里的SetItemCheckState会再次引发ItemCheck事件,这样构成了死循环
}
else
{
trackNum++;     //这里trackNum记录循环变量,当SetItemCheckState再次触发ItemCheck事件的时候不至于让i值不变
this.checkedListBox1.SetItemCheckState(i,CheckState.Checked);
}
}
} private void clb_OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.blnMouseClick=true;   //这里改动blnMouseClick其值为true,让index变量能够记录鼠标点击的那个项目索引
this.trackNum=0;           //trackNum恢复为0,以便让ItemCheck里的事件进入新一轮的循环
}
}
}