C# listbox.item是对象还是字符串?C
在今天的考试中收到以下问题,我不知道: listbox.item是字符串还是对象 有人能帮我清理一下吗?这是一个物体 读了这篇文章,你就会有了新的想法, 这是一个目标 也可以使用列表来查找字符串C# listbox.item是对象还是字符串?C,c#,string,object,listbox,C#,String,Object,Listbox,在今天的考试中收到以下问题,我不知道: listbox.item是字符串还是对象 有人能帮我清理一下吗?这是一个物体 读了这篇文章,你就会有了新的想法, 这是一个目标 也可以使用列表来查找字符串 private void FindMyString(string searchString) { // Ensure we have a proper string to search for. if (searchString != string.Empty) {
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");
}
}
试试这个
if (listBox1.DataSource == null)
{
// ----- items are string
}
else
{
//----items are object
}
看医生。他们为此而做。你确定要检查数据源是否为空吗?@nilesh先生。若在列表框中添加了项,则数据源将为空,若将数据源分配给列表框,则数据源将不为空