2016-10-13 5 views
0

テキストフィルタがうまく動作しますが、リストボックスをコンボボックスでフィルタ処理できないようです。文字列をカテゴリに変換できないという問題を解決するにはどうすればよいですか? StaffListView.xaml文字列をカテゴリに変換することができませんエラー

StaffController sc = (StaffController)Application.Current.FindResource("staffcontroller"); 
public StaffListView() 
{ 
    InitializeComponent(); 
    StaffController sc = (StaffController)Application.Current.FindResource("staffcontroller"); 
} 

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    if (e.RemovedItems.Count > 0) 
    { 
     //too much going on i think it sees the() as a method because of the ToString 
     sc.FilterBy(comboBox.SelectedItem.ToString()); 
     //MessageBox.Show("Dropdown list used to select: " + e.AddedItems[0]); 
    } 
} 

StaffControlerのパート:

public void FilterBy(Category currCategoryFilter) 
{ 
    var selected = from Staff s in MasterStaffListBasic 
        where currCategoryFilter == Category.All || s.StaffCategory == currCategoryFilter 
        select s; 
    ViewableStaffList.Clear(); 
    selected.ToList().ForEach(ViewableStaffList.Add); 
} 

EDIT:の

パート もちょうどカテゴリーを明確にすることは

+1

投稿を誹謗中傷しないでください。 – dorukayhan

答えて

1

あなた」コントローラで定義されたパブリック列挙型でありますカテゴリをパラメータとして受け取る文字列をFilterByメソッドに渡しました。あなたはcomboBox.SelectedItemを渡すが、このようなCategoryにキャストする必要があります。

entersc.FilterBy(comboBox.SelectedItem as Category); 

あなたはカテゴリーがパブリック列挙であることを特徴とする、あなたの編集に基づいて、あなたはこのようにそれを渡す必要があります。

entersc.FilterBy((Category) comboBox.SelectedItem); 

場合や、ので

entersc.FilterBy(comboBox.SelectedItem as Category? ?? (Category) 0); 

:あなたはまだas演算子を使用したいです演算子は、参照型またはNULL可能型とともに使用する必要があります。

関連する問題