We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

aaaaa wont show in my Treeview. Why?

Mickeys
Mickeys asked
on
Medium Priority
359 Views
Last Modified: 2012-05-07
I have the code below.

When I try to add "aaaaa" to my treeview it wont show up. Why? Everything else seem to work.
private void button1_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Clear();
            Contact cust = new Contact();
            cust.FirstName = textBox1.Text;
            cust.LastName = textBox1.Text;
            contactManager.Contacts.Add(cust);
 
 
 
            //listView1.Items.Add(contactManager.Contacts[0].FirstName);
            List<Contact> searchList = new List<Contact>();
 
            //Supress repainting
            treeView1.BeginUpdate();
 
            char outstr = ('A');
            
            //TreeNode node;
            for (int i = 1; i < 27; i++)
            {
                TreeNode node = treeView1.Nodes.Add(Convert.ToString(outstr));
                searchList = contactManager.FindALetterSearch(outstr);
                for (int j = 0; j < searchList.Count; j++)
                {
                    node.Nodes.Add(searchList[j].FirstName +" " +searchList[j].LastName);
                }
                outstr +=  (char)(+1);
            }
 
            textBox1.Text = "";
            //resume repainting
            treeView1.EndUpdate();
            
        }
 
-----------------------------------------------
 
 public List<Contact> FindALetterSearch(char letter)
        {            
            List<Contact> returnList = new List<Contact>();
           
            if (exists)
            {
                for (int i = 0; i < contact.Count; i++)
                {  
                    if (contact[i].LastName.ToLower().StartsWith(letter.ToString().ToLower()))
                    {
                        returnList.Add(contact[i]);
                    } //end if                                    
                } //end for
            } //end if
            
            return returnList;
        } //end Search

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:
does ur first node appear ?
 

Author

Commented:
everything appear.

A, B C......Z
if I add Andersson that will come in  BUT if I add aaaaa that wont show up

Author

Commented:
it seems to happen only when I add an a with an a after the first a. :-)

So "a"  will come up

but

"aa" wont come up

b will come up
bb will come up
CERTIFIED EXPERT

Commented:
check whether the aaaa comes in the search list or not and change ur search function as shown below
public List<Contact> FindALetterSearch(char letter)
        {            
            List<Contact> returnList = new List<Contact>();
           
            if (exists)
            {
                returnList = contact.FindAll(c=>c.LastName.ToLower
                     ().StartsWith(letter.ToString().ToLower()));
            } //end if            
            return returnList;
        } //end Search

Open in new window

Author

Commented:
I have changed the code to your suggestion. It works the same. Not change.

the aaaa comes into the searchlist

Author

Commented:
sorry.......aaaa never goes into the searchlist. So something must be wrong with the contact.FindAll ???
CERTIFIED EXPERT

Commented:
check what is the last name for 'aaaa' ?

Author

Commented:
well in the method FindALetterSearch

contacts has: Lastname aaaa
letter has: aaaaa

c => c.LastName.ToLower ().StartsWith    this I dont understand. No declaration on the c????
Anyway I cant see what that gets for value
CERTIFIED EXPERT

Commented:

returnList = contact.FindAll(c=>c.LastName.Trim().ToLower
                     ().StartsWith(letter.ToString().ToLower()));

Open in new window

Author

Commented:
no the same. Nothing getsfound with aa or aaa or aaaa and so on
CERTIFIED EXPERT

Commented:
can u try putting a trim for ur 'letter' variable also ?

Author

Commented:
nope. The same. :-(

 returnList = contact.FindAll(c => c.LastName.Trim().ToLower
                     ().StartsWith(letter.ToString().Trim().ToLower()));

Could you explain the c to me. Why dont you have to declare it? And what is c???
I am trying to debug it but dont get anything out of c

Author

Commented:
This one:
c.LastName.Trim().ToLower().StartsWith(letter.ToString().Trim().ToLower())
is false

c.LastName.Trim().ToLower()   = "aaa"
letter.ToString().Trim().ToLower() = "a"


Author

Commented:
If I add this:
c.LastName.Trim().ToLower().StartsWith("a")
is false

even if
c.LastName.Trim().ToLower()   = "aaa"
CERTIFIED EXPERT

Commented:
c => this is a lamda expression  , the first part is its decalration. u sure that nothing gets added before the name , like some special character ?

Author

Commented:
This is directly from debug mode:

"aaaa"

Thats all there is. I think this is so strange
CERTIFIED EXPERT

Commented:
can u use ToLowerInvariant instead of ToLower and see if any change is there ?

Author

Commented:
same thing. Nothing new.

 returnList = contact.FindAll(c => c.LastName.Trim().ToLowerInvariant().StartsWith(letter.ToString().Trim().ToLowerInvariant()));
CERTIFIED EXPERT

Commented:
u sure that contact is coming in the 'contact' list ?
CERTIFIED EXPERT

Commented:
if it's then this is totaly wiered i cant think of any reason why it;s not showing up in the search

Author

Commented:
I can send you my project in a zipped file to your mail if your intressted so are you able to debug.
CERTIFIED EXPERT

Commented:
u can upload it here .. no need to send mail just rename the sip as jpg and upload

Author

Commented:
sorry. but it checks whats in the jpg file

The extension of one or more files in the archive is not in the list of allowed extensions: Contact/Contact/Address.cs
CERTIFIED EXPERT

Commented:
can u try doc... ?

Author

Commented:
samething. That wont work.Sorry
CERTIFIED EXPERT

Commented:
u can sent it to gauthampj at gmail.com

Author

Commented:
and u got mail :-)
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.