简体   繁体   English

在窗体2的另一个列表框中搜索窗体1的列表框中的数据

[英]Search data in listbox in form 1 on another listbox in form2

I have a problem with this code, I want to search on listbox4 on form2 in listbox 5 on form1. 我的代码有问题,我想在form1的列表框5中的form2的listbox4上搜索。

https://i.stack.imgur.com/8d40U.jpg

I used this code as shown as below: 我使用了如下所示的代码:

int index= eski.listbox5.FindString(listbox4.ToString());
if(index= !=-1)
    eski[enter image description here][1].listbox5.SetSelected(index ,true);
else
    MessageBox.Show("Nothing Found")

Programme finds the true index value but set selected command doesn't work.. 程序找到了真实的索引值,但设置选定的命令无效。

How can I solve this problem? 我怎么解决这个问题?

listbox4.ToString() is just going to return the control as a string. listbox4.ToString()仅将控件作为字符串返回。 Call listBox4.GetItemText(listBox4.SelectedItem) instead. 而是调用listBox4.GetItemText(listBox4.SelectedItem) Also, line 2 should be if (index != -1) 另外,第二行应该是if (index != -1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM