Linux 拨号vps windows公众号手机端

ListBox中怎么获取用户选定的值

lewis 9年前 (2016-11-24) 阅读数 12 #程序编程
文章标签 listbox

要获取用户在ListBox中选定的值,可以通过SelectedIndex属性来获取选定项的索引,并通过Items集合来获取选定项的值。示例代码如下:

// 获取ListBox中选定项的索引
int selectedIndex = listBox1.SelectedIndex;

// 获取选定项的值
string selectedValue = listBox1.Items[selectedIndex].ToString();

// 输出选定项的值
Console.WriteLine(selectedValue);

在上面的代码中,假设listBox1是一个ListBox控件,通过SelectedIndex属性获取用户选定项的索引,然后通过Items集合获取该索引对应的项的值,最后输出选定项的值。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门