Question

I'm fairly new to Silverlight.

I have an AutoCompleteBox which is filled with Data retrieved from a Webservice. The Webservice talks to a MSSQL Server. I also have a DataGrid to display some information.

The AutoCompleteBox ItemsSource is bound to a List<Car> . Naturally when I try to use the AutoCompleteBox the ToString() method is called to display a String in the autocompletebox.

My DataGrid has a column that also uses a Car Object. So again the ToString() method is called. I override my ToString() Method for the DataGrid, but as I advanced in programming I got stuck with the AutoCompleteBox. Because I want it to display different String instead of what ToString of the Car Object returns.

Is it possible to define something like a method that does the same thing as ToString() so the AutoCompleteBox will use that instead of the Car Object ToString method? If so, how would I define this in the XAML part?

Thanks in advance,

Grant

Was it helpful?

Solution

Add a property to your Car class that you want be displayed in your AutoCompleteBox lets call it DisplayName but you can call it what you want.

Now add specify this property in the ValueMemberPath property of the AutoCompleteBox, something like:-

<AutoCompleteBox ItemsSource="{Binding Whatever}" ValueMemberPath="DisplayName" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top