DataGridViewCheckBoxColumn.IndeterminateValue 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置对应于不确定或 null
单元格值(显示为禁用复选框)的基础值。
public:
property System::Object ^ IndeterminateValue { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object IndeterminateValue { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))>]
member this.IndeterminateValue : obj with get, set
Public Property IndeterminateValue As Object
属性值
一个 Object,表示将被此列中单元格视为不确定值的一个值。 默认值为 null
。
- 属性
例外
CellTemplate 属性的值为 null
。
示例
下面的代码示例使用 a DataGridViewCheckBoxColumn 跟踪办公室照明的状态。 该属性将“turnedOff”与,该FalseValue属性将“turnedOn”与true
关联,并且该IndeterminateValue属性将“unknown”与不确定TrueValue关联。false
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
using namespace System::Windows::Forms;
public enum class LightStatus
{
Unknown,
TurnedOn,
TurnedOff
};
public ref class TriValueVirtualCheckBox: public Form
{
private:
DataGridView^ dataGridView1;
private:
const int initialSize;
private:
Dictionary<int, LightStatus>^ store;
public:
TriValueVirtualCheckBox() : Form(), initialSize(500)
{
dataGridView1 = gcnew DataGridView();
store = gcnew Dictionary<int, LightStatus>();
Text = this->GetType()->Name;
for(int i = 0; i < initialSize; i++)
{
store->Add(i, LightStatus::Unknown);
}
Controls->Add(dataGridView1);
dataGridView1->VirtualMode = true;
dataGridView1->AllowUserToDeleteRows = false;
dataGridView1->CellValueNeeded +=
gcnew DataGridViewCellValueEventHandler(
this, &TriValueVirtualCheckBox::dataGridView1_CellValueNeeded);
dataGridView1->CellValuePushed +=
gcnew DataGridViewCellValueEventHandler(
this, &TriValueVirtualCheckBox::dataGridView1_CellValuePushed);
dataGridView1->Columns->Add(CreateCheckBoxColumn());
dataGridView1->Rows->AddCopies(0, initialSize);
}
private:
DataGridViewCheckBoxColumn^ CreateCheckBoxColumn()
{
DataGridViewCheckBoxColumn^ dataGridViewCheckBoxColumn1
= gcnew DataGridViewCheckBoxColumn();
dataGridViewCheckBoxColumn1->HeaderText = "Lights On";
dataGridViewCheckBoxColumn1->TrueValue = LightStatus::TurnedOn;
dataGridViewCheckBoxColumn1->FalseValue =
LightStatus::TurnedOff;
dataGridViewCheckBoxColumn1->IndeterminateValue
= LightStatus::Unknown;
dataGridViewCheckBoxColumn1->ThreeState = true;
dataGridViewCheckBoxColumn1->ValueType = LightStatus::typeid;
return dataGridViewCheckBoxColumn1;
}
#pragma 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;
}
#pragma endregion
};
[STAThread]
int main()
{
Application::Run(gcnew TriValueVirtualCheckBox());
}
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);
Controls.Add(dataGridView1);
dataGridView1.VirtualMode = true;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.CellValueNeeded += new
DataGridViewCellValueEventHandler(dataGridView1_CellValueNeeded);
dataGridView1.CellValuePushed += new
DataGridViewCellValueEventHandler(dataGridView1_CellValuePushed);
dataGridView1.Columns.Add(CreateCheckBoxColumn());
dataGridView1.Rows.AddCopies(0, initialSize);
}
private DataGridViewCheckBoxColumn CreateCheckBoxColumn()
{
DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1
= new DataGridViewCheckBoxColumn();
dataGridViewCheckBoxColumn1.HeaderText = "Lights On";
dataGridViewCheckBoxColumn1.TrueValue = LightStatus.TurnedOn;
dataGridViewCheckBoxColumn1.FalseValue = LightStatus.TurnedOff;
dataGridViewCheckBoxColumn1.IndeterminateValue
= 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;
}
#endregion
[STAThreadAttribute()]
public static void Main()
{
Application.Run(new TriValueVirtualCheckBox());
}
}
public enum LightStatus
{
Unknown,
TurnedOn,
TurnedOff
};
Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class TriValueVirtualCheckBox
Inherits System.Windows.Forms.Form
Dim WithEvents dataGridView1 As New DataGridView
Const initialSize As Integer = 500
Dim store As New Dictionary(Of Integer, LightStatus)
Public Sub New()
MyBase.New()
Text = Me.GetType().Name
Dim index As Integer = 0
For index = 0 To initialSize
store.Add(index, LightStatus.Unknown)
Next
Controls.Add(dataGridView1)
dataGridView1.VirtualMode = True
dataGridView1.AllowUserToDeleteRows = False
dataGridView1.Columns.Add(CreateCheckBoxColumn())
dataGridView1.Rows.AddCopies(0, initialSize)
End Sub
Private Function CreateCheckBoxColumn() As DataGridViewCheckBoxColumn
Dim dataGridViewCheckBoxColumn1 _
As New DataGridViewCheckBoxColumn()
dataGridViewCheckBoxColumn1.HeaderText = "Lights On"
dataGridViewCheckBoxColumn1.TrueValue = LightStatus.TurnedOn
dataGridViewCheckBoxColumn1.FalseValue = LightStatus.TurnedOff
dataGridViewCheckBoxColumn1.IndeterminateValue = _
LightStatus.Unknown
dataGridViewCheckBoxColumn1.ThreeState = True
dataGridViewCheckBoxColumn1.ValueType = GetType(LightStatus)
Return dataGridViewCheckBoxColumn1
End Function
#Region "data store maintance"
Private Sub dataGridView1_CellValueNeeded(ByVal sender As Object, _
ByVal e As DataGridViewCellValueEventArgs) _
Handles dataGridView1.CellValueNeeded
e.Value = store(e.RowIndex)
End Sub
Private Sub dataGridView1_CellValuePushed(ByVal sender As Object, _
ByVal e As DataGridViewCellValueEventArgs) _
Handles dataGridView1.CellValuePushed
store.Item(e.RowIndex) = CType(e.Value, LightStatus)
End Sub
#End Region
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.Run(New TriValueVirtualCheckBox())
End Sub
End Class
Public Enum LightStatus
Unknown
TurnedOn
TurnedOff
End Enum
注解
TrueValue属性FalseValue和IndeterminateValue属性确定这些状态的关联值,因为它们在基础数据源中发生。
获取或设置此属性获取或设置 IndeterminateValue 属性返回 CellTemplate 的单元格对象的属性。 设置此属性还会设置 IndeterminateValue 列中每个单元格的属性,并刷新列显示。 若要替代单个单元格的指定值,请设置列值后设置单元格值。