0

In my Windows Phone app, I'm overriding the OnNavigatedTo method to populate a RadListPicker with some information. I have two arrays: one is a pre-filled DateTime array of size n, the second is a pre-filled string array of size n. I wanted to assign these two arrays to the RadListPicker, such that the string array is what's displayed i.e. what the user sees as choices, and the DateTimeArray to be what RadListPicker.SelectedValue returns.

When I tried it this way, I got a debugger break

private void ShowResults(DateTime[] arrayDateTime, string[] arrayString, timeTypeEnum timeType)
        {
            radListPicker.ItemsSource = arrayString;
            radListPicker.SelectedValue = arrayDateTime;
            radListPicker.SelectedIndex = 4;
}

How can I fix this?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Freakishly
  • 1,533
  • 5
  • 32
  • 61
  • which line does it jump out of the second line when you run the debugger...? – MethodMan Feb 20 '13 at 19:56
  • Freakishly, I would actually change the DataType of the Arrays to List<> and it seems to be easier to assign the ItemsSource to a list rather than an array.. I've only done this with List<> here is a Telerik Link showing how to do that http://www.telerik.com/help/windows-phone/radlistpicker-getting-started.html – MethodMan Feb 20 '13 at 20:01
  • could you do something like this as well `radListPicker.ItemsSource = new string[] {arrayString};` – MethodMan Feb 20 '13 at 20:10
  • DJ KRAZE, If I comment out the radListPicker.SelectedValue line, it doesn't break. I will give the Telerik sample a try. As for setting ItemsSource, the problem isn't that it's not picking up the string's value. The problem is that it should be picking up the DateTime value along with the String value – Freakishly Feb 20 '13 at 21:00
  • this value `arrayDateTime` is a DateTime[] Array so you need to have selected ItemIndex or some ordinal value for example `radListPicker.SelectedValue = arrayDateTime[radListPicker.SelectedItemIndex]` for example – MethodMan Feb 20 '13 at 21:04
  • I went with that last suggestion. If you want to have it as an answer, I can mark it as such =) – Freakishly Feb 24 '13 at 02:41
  • Please mark it as an answer as others may be looking for this. – mbcrump Apr 16 '13 at 20:48

2 Answers2

0

Freakishly , this value arrayDateTime is a DateTime[] Array so you need to have selected ItemIndex or some ordinal value for example

radListPicker.SelectedValue = arrayDateTime[radListPicker.SelectedItemIndex];
MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

You are mixing types here. First you are populating items of type string to the list picker. Then, later you tell the list picker to select values of type DateTime. You need to make sure that both arrays contain the same types (e.g. two arrays with string objects or two arrays with DateTime objects).

Doing a quick search on Google I found that settings the selected items can also be done using

radListPicker.SelectedItems.Add();

So in your case, when both arrays have elements of the same type you can use:

private void ShowResults(DateTime[] selectedItems, DateTime[] allItems, timeTypeEnum timeType)
{
    radListPicker.ItemsSource = allItems;
    for (var item in selectedItems)
        radListPicker.SelectedItems.Add(item);
}
Stephan
  • 1,791
  • 1
  • 27
  • 51