Basic usage of ListBox

Function: List box, used to display data in the form of a list.

Common properties:

Allow multiple columns to display data

 Add a collection of data items

 

Common events:

This event is triggered when the selection changes

 Backend code demonstration:

 //列表框项目选择变化时被触发
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("选择项编号为:"+(listBox1.SelectedIndex+1).ToString());
            MessageBox.Show("选择的内容为:"+listBox1.SelectedItem.ToString());

            //向列表框中添加内容
            listBox1.Items.Add("添加的项目");
            
            //获取列表的一些信息
            listBox1.SelectionMode=SelectionMode.MultiSimple; //允许多选
            listBox1.SelectedIndex = 0; //默认选中第一个
        }

Guess you like

Origin blog.csdn.net/XiaoWang_csdn/article/details/131774920