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/

相关文章:

matrix - 在 SWI prolog 中添加两个矩阵

matlab - Matlab 矩阵中非连续预定义值的出现顺序

c# - WPF 绑定(bind)语法

c# - 如何访问面板中的控件在 C# 中

c# - 获取 CheckBoxList 的 ValueMembers

C# 创建动态按钮和 onClick 动态事件处理程序

perl - 如何在perl中对全数字矩阵进行排序

c# - 仅针对发布版本从项目文件中删除注释

c# - 需要一些正则表达式的帮助

c# - 如何在GridControl中最佳拟合(所有列)