2024年3月15日发(作者:)
一、
DataGridView 取得或者修改当前单元格的内容:
当前单元格指的是 DataGridView 焦点所在的单元格,它可以通过 DataGridView 对象的
CurrentCell 属性取得。如果当前单元格不存在的时候,返回Nothing(C#是null)
// 取得当前单元格内容
ine();
// 取得当前单元格的列 Index
ine(Index);
// 取得当前单元格的行 Index
ine(ex);
另外,使用 tCellAddress 属性(而不是直接访问单元格)来确定单元格
所在的行:tCellAddress.Y 和列: tCellAddress.X 。这对
于避免取消共享行的共享非常有用。
当前的单元格可以通过设定 DataGridView 对象的 CurrentCell 来改变。可以通过
CurrentCell 来设定
DataGridView 的激活单元格。将 CurrentCell 设为 Nothing(null) 可以取消激活的单元格。
// 设定 (0, 0) 为当前单元格
tCell = DataGridView1[0, 0];
在整行选中模式开启时,你也可以通过 CurrentCell 来设定选定行。
/**////
/// 向下遍历
///
///
///
private void button4_Click(object sender, EventArgs e)
...{
int row = + 1;
if (row > nt - 1)
row = 0;
tCell = idView1[0, row];
}
/**////
/// 向上遍历
///
///
///
private void button5_Click(object sender, EventArgs e)
...{
int row = - 1;
if (row < 0)
row = nt - 1;
tCell = idView1[0, row];
}
* 注意: idView 的索引器的参数是: columnIndex, rowIndex 或是 columnName,
rowIndex
这与习惯不同。


发布评论