将数据从数据库设置为列表框

时间:2015-12-17 15:47:37

标签: c# wpf azure listbox

我在Azure中有数据库并且我创建了表: Table 我将数据从“类别”列发送到listbox1,我希望从“类型”表中将数据发送到listbox2,其中元素“类别”与列表框1中的选定项目相同。例如:当在listbox1中选择'Food'时,listbox2显示'Fruit'。 我试过这个,但它不起作用:

  private async void ViewType(string cat)      
{
       MobileServiceCollection<string, string> result = null;
        MobileServiceInvalidOperationException exception = null;
        try
        {
        result = await todoTable.Where(TodoItem => TodoItem.Category == cat)
                .Select(todoItem => todoItem.Type)
                .ToCollectionAsync();

        }
        catch (MobileServiceInvalidOperationException ex)
        {
            exception = ex;
        }

        if (exception != null)
        {
            await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
        }
        else
        {
            ListBox2.ItemsSource = result.Distinct(); 
        }
    }

 private void ListBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        string _category = ListBox1.SelectedItem.ToString();
        ViewType(_category);
    }

有人知道出了什么问题吗?

0 个答案:

没有答案