I have a datagridview which I fill it as below :
var q= repository.GetStudents();//
dataGridView1.DataSource = null;
dataGridView1.Columns.Clear();
dataGridView1.DataSource = q;
dataGridView1.Columns.RemoveAt(1);
//Remove IsActive
//Cause I want to have my own implementation
dataGridView1.Columns[0].DataPropertyName = "StudentID";
dataGridView1.Columns[0].HeaderText = "Studunet ID";
dataGridView1.Columns[1].DataPropertyName = "IsActive";
dataGridView1.Columns[1].HeaderText = "Status";
The “IsActive” property is of boolean Type. When the “IsActive” cell is being displayed, it show true/false. I want to replace it with my own custom value.
I read this and this posts but I could not resolve my problem.
You can use the
CellFormattingevent of theDataGridView, e.g.:EDIT (as per comment):
It’s very similar to what you’re doing now, just remove the bound column and add a new column of the desired type and set the
DataPropertyNameproperly e.g. :Note that this append the column at the end, but you can decide the position of the column by using
dataGridView.Columns.Insertmethod instead ofAdd.