[英]Unselect listbox when other one is selected
以下代碼可能會幫助您解決問題,但是您也可以在函數的selectedIndexChanged事件上添加clearSelected函數。
namespace StackoverFlow4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Text = "UnSelected";
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
button1.Text = "Selected";
pictureBox1.BackgroundImage = StackoverFlow4.Properties.Resources.tick;
button1.Text = "Clear Selected";
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.ClearSelected();
listBox2.ClearSelected();
button1.Text = "UnSelected";
pictureBox1.BackgroundImage = StackoverFlow4.Properties.Resources.cross;
pictureBox2.BackgroundImage = StackoverFlow4.Properties.Resources.cross;
}
private void listBox2_SelectedValueChanged(object sender, EventArgs e)
{
pictureBox2.BackgroundImage = StackoverFlow4.Properties.Resources.tick;
button1.Text = "Clear Selected";
}
}
}
首先兩者都未被選中 清除列表(如果要選擇) 如果兩者都選中,則清除兩者
我在這里太新了,為壞處和物品感到抱歉
您只需要在相應的列表框上為SelectedIndexChange添加一個事件偵聽器,如下所示:
// Have Box1 deselect any Box2 inputs on index change.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
listBox2.ClearSelected();
}
// Have Box2 deselect any Box1 inputs on index change.
private void listBox2_SelectedIndexChanged(object sender, EventArgs e) {
listBox1.ClearSelected();
}
要檢出的其他資源: 取消選擇列表框中的所有項目
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.