DataGridExtensions + DataView #100
-
Hello, I am using DataView to display data in DataGrid and enable "DataGridFilter.IsAutoFilterEnabled" but it doesn't work... I can see the filter icon, I can write text, but the data in the DataGrid is not filtered. Can you tell me this functionality is not included? Or maybe i am doing something wrong? .Net Framework 4.8 <Window x:Class="TestExtDataGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestExtDataGrid"
xmlns:dgx="clr-namespace:DataGridExtensions;assembly=DataGridExtensions"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<DataGrid Name="Table" dgx:DataGridFilter.IsAutoFilterEnabled="True"/>
</Grid>
</Window> namespace TestExtDataGrid
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public List<Model> Items = new List<Model>();
public MainWindow()
{
InitializeComponent();
Items.Add(new Model { Name = "test", Age = 1, DateBorn = DateTime.Now });
Items.Add(new Model { Name = "test2", Age = 2, DateBorn = new DateTime(2020, 1, 1) });
Items.Add(new Model { Name = "test0", Age = 0, DateBorn = new DateTime(2020, 2, 1) });
Items.Add(new Model { Name = "test1", Age = 0, DateBorn = new DateTime(2020, 3, 1) });
Items.Add(new Model { Name = "test2", Age = 0, DateBorn = new DateTime(2020, 4, 1) });
Items.Add(new Model { Name = "test2", Age = 0, DateBorn = new DateTime(2020, 1, 2) });
Items.Add(new Model { Name = "test7", Age = 7, DateBorn = new DateTime(2020, 1, 1) });
DataTable table = new DataTable();
table.Columns.Add("IsSelect", typeof(bool));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Age", typeof(int));
table.Columns.Add("DateBorn", typeof(DateTime));
Items.ForEach(item => table.Rows.Add(item.IsSelect,item.Name, item.Age, item.DateBorn));
Table.ItemsSource = table.DefaultView;
}
}
public class Model
{
public bool IsSelect { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public DateTime DateBorn { get; set; }
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I think this is a good WPF approach to get dynamic columns: public MainWindow()
{
InitializeComponent();
DataGrid.ItemsSource = new ObservableCollection<object>
{
CreateItem(true, "Value1"),
CreateItem(false, "Value2"),
CreateItem(true, "Value3"),
CreateItem(false, "Value4")
};
DataGrid.Columns.Add(new DataGridCheckBoxColumn() { Binding = new Binding("Column1") });
DataGrid.Columns.Add(new DataGridTextColumn() { Binding = new Binding("Column2") });
}
static object CreateItem(bool col1, string col2)
{
var item = (IDictionary<string, object?>)new ExpandoObject();
item["Column1"] = col1;
item["Column2"] = col2;
return item;
} |
Beta Was this translation helpful? Give feedback.
I think this is a good WPF approach to get dynamic columns: