长话短说,我有这个 dataGridView,我希望单元格 [0,0] 成为网格左下角的单元格,而不是像默认情况下那样位于网格的左上角。
例如,在视觉上,如果我做类似的事情:
dataGridView1[0, 0].Value = "a";
I get this (sorry not enough reputation to post pictures)
但我希望“a”出现,通过执行相同的指令,在蓝色突出显示的插槽中,并通过添加行之类的操作将其添加到网格的顶部。
非常感谢和问候
最佳答案
像这样创建一个类:
public class MyDataGridView : DataGridView
{
public new DataGridViewCell this[int col, int invertRow]
{
get
{
int recordCount = this.RowCount - (this.AllowUserToAddRows ? 2 : 1);
return this.Rows[recordCount - invertRow].Cells[col];
}
set
{
int recordCount = this.RowCount - (this.AllowUserToAddRows ? 2 : 1);
this.Rows[recordCount - invertRow].Cells[col] = value;
}
}
}
然后这样调用:
dataGridView1[0, 0].Value = "a";
或者如果你只想设置或获取网格左上角的第一个单元格,那么你可以使用 FirstDisplayedCell属性(property)。
MSDN: Gets or sets the first cell currently displayed in the DataGridView; typically, this cell is in the upper left corner.
例如:
dataGridView1.FirstDisplayedCell.Value = "a";
关于c# - Windows 窗体 : change dataGridView's first cell origin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30785816/