I load a DataGridView through a list.
datagridview.DataSource = listaVariables;
This DatagridView, is formed by a column (the first) that is of the DataGridViewCheckBoxCell type.
What I want to do is that, depending on a property of the variables in the list, it is activated as marked or not.
I've tried to do this:
datagridview.Rows[pos].Cell[0].Value = true; //pos es un entero que utilizo para recorrer las filas y pongo 0 en Cell porque es la primera columna la que tiene los CheckBox
and does nothing, leaves it unmarked.
I have also tried to create a cell of the DataGridViewCheckBoxCell type, starting it true but it does not work either, it gives me an error of formatting the cell (System.FormatException: The formatted value of the cell has an erroneous type):
DataGridViewCheckBoxCell dC = new DataGridViewCheckBoxCell(true);
datagridview.Rows[pos].Cell[0] = dC;
In this last test I think that the cell that I believe (although I do not allow it to be assigned) that I would not put the checkbox that contains true.
I've also tried to do:
dataGridView.Rows[pos].SetValues(true); //Se supone que la primera celda de la fila la debería poner a true y no lo hace
and
var values = new bool[] { true };
dataGridView.Rows[pos].SetValues(values);
and I still have the same result, it does not show me the activated checkbox.
The list with which I charge the datagrid I define it like this:
List<PlacaVariableP> listaVariables;
The Variable object is as follows:
public class PlacaVariableP:IComparable
{
public virtual long id_placavariable { get; set; }
public virtual long idplaca { get; set; }
public virtual string descripcion { get; set; }
public virtual string unidades { get; set; }
public virtual string idFichero { get; set; }
public virtual int CompareTo(object obj)
{
PlacaVariableP c = (PlacaVariableP)obj;
return String.Compare(this.descripcion, c.descripcion, StringComparison.Ordinal);
}
public virtual void toString(object obj)
{
obj.ToString();
}
}