It seems ok, but hard to say with that less code. What I would do is to add a line after linq query.
var qres = files.ToList();
and put a breakpoint at datagrid.datasource set line. when your debugger hits that line qres will show your actual data if any. I think there is something wrong with your data.
I added a sample as the following:
[updated]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test_Grid2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitOthers();
}
DataGridViewTextBoxColumn colName;
DataGridViewTextBoxColumn colSize;
DataGridViewCheckBoxColumn colSelected;
private void InitOthers()
{
this.colName = new DataGridViewTextBoxColumn()
{
Name = "colName",
HeaderText = "Name",
DataPropertyName = "Name",
ValueType = typeof(string)
};
this.colSize = new DataGridViewTextBoxColumn()
{
Name = "colSize",
HeaderText = "Size",
DataPropertyName = "Size",
ValueType = typeof(string)
};
this.colSelected = new DataGridViewCheckBoxColumn()
{
Name = "colSelected",
HeaderText = "Seleccionado",
DataPropertyName = "Selected",
Resizable = DataGridViewTriState.True,
SortMode = DataGridViewColumnSortMode.NotSortable,
ValueType = typeof(bool)
};
this.dataGridView1.Columns.Add(this.colName);
this.dataGridView1.Columns.Add(this.colSize);
this.dataGridView1.Columns.Add(this.colSelected);
}
private void button_Fill_Click(object sender, EventArgs e)
{
IEnumerable<FileRecord> library;
library = new List<FileRecord>()
{
new FileRecord() { Name = "file1", Size = "10", Selected = false },
new FileRecord() { Name = "file2", Size = "20", Selected = false },
new FileRecord() { Name = "file3", Size = "30", Selected = false }
};
this.dataGridView1.DataSource = library;
this.dataGridView1.Refresh();
this.dataGridView1.Columns["colSelected"].ReadOnly = true;
}
}
public class FileRecord
{
public string Name { get; set; }
public string Size { get; set; }
public bool Selected { get; set; }
}
}