四个combobox的下拉框选项都为1.2.3.4,在如果选项中的1被选后,其他的combobox就不能继续选择1,其他的也一样
3条回答 默认 最新
- CSDN专家-showbo 2022-03-31 12:26关注
添加SelectedIndexChanged事件,然后用数组的记录住每个combox选中的值,判断已经存在则还原为原来的值,示例代码如下
4个combobox的SelectedIndexChanged全部选择comboBox_SelectedIndexChanged这个处理函数
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Data.SqlClient; namespace WindowsFormsApp8 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int[] texts = new[] { -1, -1, -1, -1 }; private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { var o = (ComboBox)sender; var index = int.Parse(o.Name.Replace("comboBox", "")) - 1;//注意combobox的name起得有规律,依次为comboBox1~comboBox4 var SelectedIndex = o.SelectedIndex; if (SelectedIndex == -1) return; if (texts.Contains(SelectedIndex)) { MessageBox.Show("已经选过!"); o.SelectedIndex = texts[index];//还原 } else texts[index] = SelectedIndex; } private void button1_Click(object sender, EventArgs e) { texts = new[] { -1, -1, -1, -1 }; comboBox1.SelectedIndex = comboBox2.SelectedIndex = comboBox3.SelectedIndex = comboBox4.SelectedIndex = -1; } } }
有其他问题可以继续交流~本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 mbedtls握手返回-7200
- ¥30 c++ http服务器
- ¥15 express连接mssql,每条额外附加了语句
- ¥20 IQOO12如何有效ADB方法
- ¥15 ios如何获取用户的订阅情况
- ¥15 复杂表达式求值程序里的函数优先级问题
- ¥15 求密码学的客成社记ji着用
- ¥35 POI导入树状结构excle
- ¥15 初学者c语言题目解答
- ¥15 div editable中的光标问题