Here I will post problems I and my colleagues met and solutions we found.

Friday, September 19, 2008

ComboBox - DisplayMemberPath or TextSearch.TextPath

Probably it's just too late already, and I am slow, but I was confused with DisplayMemberPath and TextSearch.TextPath properties.

First, I added some objects to ComobBox.Items. Not using XML, I did it dynamically from C#. It worked find on Vista computer, but then it didn't work under XP. I just got empty values instead of value of ToString() method.

OK, I looked in my favorite book WPF Unleashed, and found that TextSearch.TextPath should be used. Well, it didn't help. It took me a while until I got to try old familiar DisplayMemberPath property and then it worked.

So, the question I have now is why TextSearch.TextPath didn't work? Or if asked in more general way, what are the rules. When I am supposed to use DisplayMemberPath and when TextSearch.TextPath. Anybody?

3 comments:

Unknown said...

Didn't get it - what did you use TextPath for? Binding? Maybe post a code fragment.

Maxim Alexeyev said...

You right. That's what I tried to do, use TextPath for binding. Thanks.

Unknown said...

Still fuzzy...
If you want to customize all content display, DisplayMemberPath should be used
For selected one, SelectedMemberPath.
For textbox on the top, TextSearch.

DisplayMemberPath works for everything, so when you switched to it, everything including textbox has changed.

As of why it worked under vista and not XP, I'm curious myself - but probably the reason is the difference in parsing of the path string - what did you set it to?

If your items are dependency objects, you might try myitem.setvalue(textsearch.text, "bla");