【发布时间】:2013-08-22 23:07:00
【问题描述】:
所以我昨天写了this question。我仍在使用 UPDATE 下的解决方案,但由于某种原因,我现在收到 FormatException was Unhandled 错误。在错误下,编译器窗口显示Input string was not in a correct format。为什么会发生这种情况?
当我查看错误时,我认为使用Int32.TryParse 可能会更好,就像在this link 中一样。但这几乎是一样的交易。
这是我目前拥有的......
//Initializing a parent TreeView Item
TreeViewItem parentItem = (TreeViewItem)SelectedItem.Parent;
//This is the call to getNumber that I am having trouble with.
//It is located in an if statement, but I didn't bother to write out the
//whole statement because I didn't want to add surplus code
int curNumber = getNumber(parentItem.Header.ToString());
//Gets the number contained in a Node's header
public static int getNumber(string parentNodeHeader)
{
int curNumber = 0;
curNumber = Convert.ToInt32(parentNodeHeader); //**FormatException!!
return curNumber;
}
注意:我单击以显示此错误的节点中没有数字值。但是,他们的父母这样做(这是我不明白的,因为我将父母的header 传递给函数)。
感谢您的帮助!
【问题讨论】:
标签: c# wpf treeview formatexception