Hi. I'm developing a small application in WPF. I have a ListBox
named NameListBox
whose ItemsSource
property is set to a DataView
, and thus displays a list of customer names. The name is composed of 3 parts: FirstName
, MiddleName
, and LastName
. I have used a converter to display the full name of customer in the list. Everything works fine (and I think this level of detail is enough to get the overall picture).
Now I want to enable filtering on the NameListBox
such that the list should only displat those customer names that contain the text entered in the TextBox
named CustomerNameSearchBox
.
By searching on the Internet I came across RowFilter
property of DataView
- and also played with that a little. Now when I tried
private void CustomerNameSearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
//((DataView)NameListBox.ItemsSource).RowFilter = @"COALESCE(FirstName+' '+MiddleName+' '+LastName, COALESCE(FirstName+' '+LastName, COALESCE(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
((DataView)NameListBox.ItemsSource).RowFilter = @"ISNULL(FirstName+' '+MiddleName+' '+LastName, ISNULL(FirstName+' '+LastName, ISNULL(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
}
This thing gave me expected results. But wait.. there's something strange here!!!
As you can see, the structure of both lines is the same - only COALESCE
in place of ISNULL
. But when I uncomment the first line (and comment out the second) it does't work!!!! It throws an exception at runtime at that line saying "The expression contains undefined function call COALESCE()."
!!!!
Though ISNULL
serves my purpose at this moment, I'm really curious to know why this exception happens. Moreover, even a simple thing like
(...).RowFilter = @"COALESCE(FirstName,'')";
doesn't seem to work!!!! (It means its more than just a syntactical problem)
Can anyone explain me about this behavior?? Thanks in advance.
Tags : WPF SQL COALESCE ISNULL RowFilter