FalseValue Property

DataGridViewCheckBoxColumn.FalseValue Property


Gets or sets the underlying value corresponding to a cell value of false, which appears as an unchecked box.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public object FalseValue { get; set; }

Property Value

Type: System.Object

An Object representing a value that the cells in this column will treat as a false value. The default is null.

Exception Condition

The value of the CellTemplate property is null.

The FalseValue, TrueValue, and IndeterminateValue properties determine the associated values of these states as they occur in the underlying data source.

Getting or setting this property gets or sets the FalseValue property of the cell object returned by the CellTemplate property. Setting this property also sets the FalseValue property of every cell in the column and refreshes the column display. To override the specified value for individual cells, set the cell values after you set the column value.

The following code example uses a DataGridViewCheckBoxColumn to track the status of office lighting. The FalseValue property associates "turnedOff" with false, the TrueValue property associates "turnedOn" with true, and the IndeterminateValue property associates "unknown" to indeterminate.

using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;

public class TriValueVirtualCheckBox:Form
    DataGridView dataGridView1 = new DataGridView();

    const int initialSize = 500;

    Dictionary<int, LightStatus> store 
        = new Dictionary<int, LightStatus>();

    public TriValueVirtualCheckBox() : base()
        Text = this.GetType().Name;

        int index = 0;
        for(index=0; index<=initialSize; index++)
            store.Add(index, LightStatus.Unknown);

        dataGridView1.VirtualMode = true;
        dataGridView1.AllowUserToDeleteRows = false;
        dataGridView1.CellValueNeeded += new 
        dataGridView1.CellValuePushed += new 

        dataGridView1.Rows.AddCopies(0, initialSize);

    private DataGridViewCheckBoxColumn CreateCheckBoxColumn()
        DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1 
            = new DataGridViewCheckBoxColumn();
        dataGridViewCheckBoxColumn1.HeaderText = "Lights On";
        dataGridViewCheckBoxColumn1.TrueValue = LightStatus.TurnedOn;
        dataGridViewCheckBoxColumn1.FalseValue = LightStatus.TurnedOff;
            = LightStatus.Unknown;
        dataGridViewCheckBoxColumn1.ThreeState = true;
        dataGridViewCheckBoxColumn1.ValueType = typeof(LightStatus);
        return dataGridViewCheckBoxColumn1;

#region "data store maintance"
    private void dataGridView1_CellValueNeeded(object sender, 
        DataGridViewCellValueEventArgs e)
        e.Value = store[e.RowIndex];

    private void dataGridView1_CellValuePushed(object sender, 
        DataGridViewCellValueEventArgs e)
        store[e.RowIndex] = (LightStatus) e.Value;

    public static void Main()
        Application.Run(new TriValueVirtualCheckBox());

public enum LightStatus

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft