listbox.item是对象还是字符串?C#
本文关键字:字符串 对象 item listbox | 更新日期: 2023-09-27 18:28:50
今天在一次考试中收到了以下问题,我对此一无所知:
listbox.item
是字符串还是对象?
有人能帮忙清理一下吗?
阅读本文并获得想法,它是一个对象http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem%28v=vs.110%29.aspx
也可以使用FindString 的列表
private void FindMyString(string searchString)
{
// Ensure we have a proper string to search for.
if (searchString != string.Empty)
{
// Find the item in the list and store the index to the item.
int index = listBox1.FindString(searchString);
// Determine if a valid index is returned. Select the item if it is valid.
if (index != -1)
listBox1.SetSelected(index,true);
else
MessageBox.Show("The search string did not match any items in the ListBox");
}
}
它是一个对象
ListBox.Items属性
尝试这个
if (listBox1.DataSource == null)
{
// ----- items are string
}
else
{
//----items are object
}