DataGrid中添加个复选框
决定做一个可重用的控制,将增加一个复选框DataGrid
。
然后添加复选框列到DataGrid
:
该CheckBoxColumn
类相当简单:
2个属性:
SelectedDataKeys:返回一个ArrayList
使用DataKey
值
SelectedIndexes:
Returns anInt32 []
with theselectedIndex
valuesSelectedIndexes:
返回一个Int32 []
与selectedIndex
值要找出复选框被选中:
这几乎是它的
DataKeyField
的DataGrid
可以是任何类型。 The sample I've included binds aDataTable
to theDataGrid
, you can change theDataKeyField
from "ID
" (int
) to "Name
" (string
) to see the code working with different types.所包含的示例中,我已经绑定了一个DataTable
到DataGrid
,你可以改变DataKeyField
由“ID
“(int
),以“Name
“(string
)来查看代码类型使用不同的。