Click here to Skip to main content
15,948,339 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have the following codes to display results in a TreeView. But I keep on getting the error message as the title above. May I know how can I solve it? Below are my codes:

C#
private void PopulateQuestionTree(bool isDelete)
{
    tvQuestionList.BindingContext = null;
    tvQuestionList.Nodes.Clear();
    CustomDataCollectionQuestionDtoList questionList = new       CustomDataCollectionQuestionDtoList();
    questionList.DtoList = _customDataCollectionQuestionList.DtoList.Where(q =>
        q.TrackingState != BaseDto.TrackingInfo.Deleted).OrderBy(q => q.Sequence).ToList();

    for (int i = 0; i < questionList.DtoList.Count; i++)
    {
        if(tvQuestionList.Nodes.Contains(x=>x.Name != questionList.DtoList[i].Name) //error here
        {
            tvQuestionList.Nodes.Insert(i, CreateTreeNode(questionList.DtoList[i], i));
        }
    }
    tvQuestionList.Refresh();
}
Posted
Comments
Sergey Alexandrovich Kryukov 22-May-15 1:36am    
What's unclear in this message? Look at the signature of the Contains method, its MSDN help page, as well as the help pages on the relevant types, and you will see what to do. If not, you have to specify full type names precisely and/or provide links to those pages. There is a number of similarly named types in different parts if FCL.

After 106 asked questions (and plus those which have been deleted due to abuse reports) you could have understood how to ask questions, if not finding the answers by yourself. Aren't you totally ignore all comments and answers written for you?

And how much longer you are going to post your fake answers and even self-accept them?

—SA

1 solution

Contains[^] is probably the wrong method: it returns a bool which says "yes, this tiem is in the list" or "no, this item is not in the list"
From the rest of your code, I suspect you want to use FirstOrDefault[^] and a test for null return.
 
Share this answer
 
Comments
Jamie888 22-May-15 1:58am    
Sir, I have one(1) data/result(let say it is "Hello"). But when the codes is being executed, it will display the same result("Hello" in this case) TWICE. How can I check if the tvQuestionList has contain the "Hello" and then the second "Hello" would not be displayed anymore?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900