안녕하세요. Combobox 아이템이 너무 많아 필터기능을 넣고자 하는데 생각만큼 쉽지가 않네요;;
막연하게 바인딩 소스에 필터를 적용해서 갱신을 했더니 초기화가 안되는 문제가 있어서
이것저것 찾아보다 Filter라는 기능과 예제 소스를 찾게 되었는데 계속해서 NotSupporedException 에러
가 뜨면서 작동이 안되네요. 도움부탁드립니다~!
<DataGridComboBoxColumn x:Name="bizColumn" Header="업 체" Width="0.3*" CellStyle="{StaticResource gridCellStyle}"
SelectedValueBinding="{Binding ItemInBiz , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Display"
SelectedValuePath="Value">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Width" Value="170"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="ItemsSource" Value="{Binding FilteredBizList}" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource itemcontainer}"/>
<Setter Property="IsTextSearchEnabled" Value="False"/>
<EventSetter Event="KeyUp" Handler="Combobox_keyup"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}" >
<Setter Property="Width" Value="160"/>
<Setter Property="ItemsSource" Value="{Binding FilteredBizList}" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource itemcontainer}"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="IsEditable" Value="True"/>
<Setter Property="IsTextSearchEnabled" Value="False"/>
<EventSetter Event="KeyUp" Handler="Combobox_keyup" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
//Filterd BizList
BizList = new BindingList<object>();
BizList.Add(new { Display = "하하", Value = "12345" });
BizList.Add(new { Display = "호호", Value = "67890" });
BizList.Add(new { Display = "카캬", Value = "AAAAA" });
BizList.Add(new { Display = "푸푸", Value = "BBBBB" });
BizList.Add(new { Display = "소소", Value = "CCCCC" });
//KeyUpEvent Handler
private void Combobox_keyup(object sender , KeyEventArgs e)
{
ComboBox comboBox = sender as ComboBox;
comboBox.Items.Filter -= this.FilterPredicate; //NotSupport 에러
this.mTextBox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox;
if (e.Key == Key.Enter || e.Key == Key.Tab || e.Key == Key.Return)
{
return;
}
else
{
comboBox.IsDropDownOpen = true;
comboBox.Items.Filter += this.FilterPredicate; //NotSupport 에러
}
}
//FilterPredicate
private bool FilterPredicate(object obj)
{
string sValue = string.Empty;
if (obj is string)
sValue = obj.ToString();
else if (obj is ComboBoxItem)
sValue = (obj as ComboBoxItem).Content.ToString();
else
{
System.Reflection.PropertyInfo info = obj.GetType().GetProperty(bizColumn.DisplayMemberPath);
if (info != null)
{
object oValue = info.GetValue(obj, null);
if (oValue != null)
{
sValue = oValue.ToString();
}
}
}
if (!string.IsNullOrEmpty(sValue) && sValue.Contains(this.mTextBox.Text)) return true; else return false;
}
}