@Peter Fleischer (former MVP) : Hi , from the datagrid column Name, i'm performing filter from textbox/combox then with radio buttons to make it easy for the user. At somepoint i want to display all the data in the datagrid column Name, so i tried to reset using the radio button by sending empty string and set the view to null but its not working. How can i reset the datagrid column Name and display all the data? thanks
Datagrid column:
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*" IsReadOnly="True"/>
The radio button which is not resetting the filter of the datagrid column Name:
<RadioButton x:Name="rreset" Content=" " Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=rreset, Path=Content}" Margin="0,0,149,0">
Other radio buttons: These buttons are working
<RadioButton x:Name="rmetallic" Content="Metallic" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=rmetallic, Path=Content}" ></RadioButton>
<RadioButton x:Name="rsticker" Content="Sticker" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=rsticker, Path=Content}" ></RadioButton>
<RadioButton x:Name="rperfo" Content="Perfo" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=rperfo, Path=Content}" Margin="0,0" ></RadioButton>
<RadioButton x:Name="rsupermatte" Content="SuperMatte" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=rsupermatte, Path=Content}" Margin="0,0" ></RadioButton>
Properties used to filter datagrid column Name:
private string _SizeSearch;
public string SizeSearch
{
get { return _SizeSearch; }
set
{
_SizeSearch = value;
OnPropertyChanged("SizeSearch");
View.Refresh();
}
}
private string _MediaType;
public string MediaType
{
get { return _MediaType; }
set
{
_MediaType = value;
OnPropertyChanged("MediaType");
View.Refresh();
}
}
Filter
private bool Filter(object item)
{
Product p = item as Product;
if (p == null) return true;
var ret = true;
if (!String.IsNullOrEmpty(MainProductSearch))
ret = ret && p.Mainproduct.IndexOf(MainProductSearch, StringComparison.OrdinalIgnoreCase) >= 0 ||
p.Name.IndexOf(MainProductSearch, StringComparison.OrdinalIgnoreCase) >= 0;
if (!String.IsNullOrEmpty(SizeSearch))
ret = ret && p.Name.IndexOf(SizeSearch, StringComparison.OrdinalIgnoreCase) >= 0;
if (SizeSearch == string.Empty)
ret = ret && p.Name.IndexOf(SizeSearch, StringComparison.OrdinalIgnoreCase) >= 0;
if (!String.IsNullOrEmpty(MediaType))
ret = ret && p.Name.IndexOf(MediaType, StringComparison.OrdinalIgnoreCase) >= 0;
if (!String.IsNullOrEmpty(Visible))
ret = ret && p.Visible.IndexOf(Visible, StringComparison.OrdinalIgnoreCase) >= 0;
return ret;
}
Realay command for radio buttons :
public ProductPriceViewModel()
{
MyCommand = new RelayCommand(executemethod, canexecutemethod);
}
//method for mediatype filter
private void executemethod(object parameter)
{
MediaType = (string)parameter; //execute radio buttons content
if (MediaType == " ") // reset filter for datagrid column Name
{
OnPropertyChanged("SizeSearch");
cvs.View.Filter = null;
View.Refresh();
}
}