Windows窗体列表框验证 [英] Windows Form Listbox Validation

查看:80
本文介绍了Windows窗体列表框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我有一个名为lst_Pending的Listbox,它有两个项目,True和False。列表框是表单的一部分,我需要在单击提交时如果您没有选择true或false,您将收到一条错误消息,询问您是否有必要选择一个。我从来没有真正使用过列表框,所以这就是我不确定的原因。


使用Listbox是否有更好的替代方法可用于真或假?

Hey guys, I've got a Listbox called lst_Pending and it has two items, True and False. The list box is a part of a form and I need to when submit is clicked if you haven't selected true or false you'll receive an error message asking you that it is necessary to pick one. I've never really used list boxes so this is why I'm not sure.

Would there be any better alternatives to using a Listbox for something that's true or false?

推荐答案

试试这个列表框

Try this for listbox
private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                 //your code logic
            }
            else
            {
                MessageBox.Show("Please select anyone");
            }
        }


这篇关于Windows窗体列表框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆