c# - Windows 窗体 : change dataGridView's first cell origin?

标签 c# winforms matrix datagridview

长话短说,我有这个 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/

相关文章:

c# - 错误 400 - 使用 Microsoft Graph 错误请求创建用户

c# - Entity Framework : "The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects."

c# - 如何在 C# 中关闭 MessageBox 后强制按钮、文本框在窗体上重新绘制

c# - 如何使图片框透明?

python - 用python中的另一个向量求和零和一

performance - 加速numpy矩阵逆

c# - 来自 C# 自定义操作的 MsiSetProperty

c# - 如何将表单控件添加到 Excel 电子表格中每一行的单元格

c# - .NET 控件类似 Outlook 的电子邮件地址文本控件

java - 如何使用 ArrayList(在 Java 中)为 1x1 矩阵编写默认构造函数?