Nodo N;
foreach (string S in listBox_nodos.Items)
{
N = graph.getNodoName(S);
string comp = (string) listBox_nodos.SelectedItem;
if (comp == S)
System.Console.WriteLine(N.NAME);
} 我得到了InvalidOperationException,应用程序崩溃了。
我不明白为什么。有什么帮助吗?谢谢。
编辑:打印'N.NAME‘!然后就崩溃了。
EDIT2:我尝试过捕捉异常,但无论如何应用程序都会崩溃。
发布于 2010-01-02 23:34:21
你在哪一行得到异常?在不知道listBox_nodos具有什么数据类型的情况下,我的第一个猜测是Items不包含大量的string,而是ListBoxItem
foreach (var item in listBox_nodos.Items)
{
N = graph.getNodoName(item.Value); // or .SomethingElse发布于 2010-01-03 00:20:21
- if you're not sure of the types involved, could get the Items/SelectedItem as IEnumerable/object and then gettype() on them and display that.
发布于 2012-06-15 04:48:51
我以前也遇到过类似的问题,也与选定的项目有关。我对它进行了广泛的调查,但没有找到解决方案。我最终重做了表单(尽管我认为只有控件是必要的),这似乎解决了它。
https://stackoverflow.com/questions/1991903
复制相似问题