新しい行を表示しないようにするには
[XAML]
<DataGrid x:Name="dgExamList" CanUserAddRows="False">
コードビハインドで列の書式を設定するには
[XAML]
<DataGridTextColumn x:Name="clDate" Binding="{Binding exam_day}"/>
[C#]
clDate.Binding.StringFormat = "yyyy/MM/dd";
DataTableをDataGridで使い、フィルターをかける
Make use of filtering of DataGrid with DataTable
[XAML]
<DataGrid x:Name="dgExamList" ItemsSource="{Binding}" AutoGenerateColumns="False">
[C#]
public partial class ExamList : Window
{
private DataTable exam_list = new DataTable();
private BindingListCollectionView cv;
public ExamList()
{
InitializeComponent();
//ここにexam_listを生成するコード。Generate exam_list
cv = new BindingListCollectionView(exam_list.DefaultView);
dgExamList.DataContext = cv;
filterGridView(filterStr.BlankDraft);
}
private enum filterStr { ShowAll, BlankDraft, Done, Checked, Canceled };
private void filterGridView(filterStr fs)
{
switch (fs)
{
case filterStr.ShowAll:
cv.CustomFilter = null;
break;
case filterStr.BlankDraft:
cv.CustomFilter = "exam_status < 2";
break;
case filterStr.Done:
cv.CustomFilter = "exam_status = 2";
break;
case filterStr.Checked:
cv.CustomFilter = "exam_status = 3";
break;
case filterStr.Canceled:
cv.CustomFilter = "exam_status = 9";
break;
}
}
}