为什么我不能在法达到的数据? [英] Why can't I reach data within Method?

查看:118
本文介绍了为什么我不能在法达到的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图通过肚里的方法来填充 TableLayoutPanel中如下:

I'm currently trying to fill a TableLayoutPanel through a method which goes as follows:

private int _rowCount;
public void InitPaths()
{
    int c = 1;
    int a = 1;

    while (a < _PathRows.Length - 1)
    {
        var label = new Label();
        //
        // Label - Format.
        //
        label.Dock = DockStyle.Fill;
        label.AutoSize = false;
        label.Text = _pfadZeilen[a];
        label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
        label.Size = new System.Drawing.Size(22, 13);
        label.BackColor = System.Drawing.Color.Transparent;
        TableLayoutP.Controls.Add(label, 3, c);

        //Checkboxen Einfügen
        var cbox = new CheckBox();
        //
        //Checkbox Format.
        cbox.Anchor = System.Windows.Forms.AnchorStyles.None;
        cbox.AutoSize = true;
        cbox.CheckAlign = System.Drawing.ContentAlignment.MiddleCenter;
        cbox.Name = "checkBoxPfad" + a;
        cbox.Size = new System.Drawing.Size(15, 14);
        cbox.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        cbox.UseVisualStyleBackColor = true;
        TableLayoutP.Controls.Add(cbox, 0, c);
        a++;
        c++;

    }

    this._rowCount = BibTable.GetRowHeights().Length; // which seems to be Holding the value only within the method
}



然后删除行动的所有行,可以通过以下方式:

and then delete all rows on Action, through the following Method:

public void RemoveRows()
{
    for (int row = _rowCount; row >= 0; row--)
    {
        BibTable.RowStyles.RemoveAt(row);
        BibTable.RowCount--;
    }
}

现在的问题是,如果我尝试做任何事情与 TableLayoutP ,其中所有行初始化的方法之外,它会告诉我:

Now the Problem is, if I try to do anything with the TableLayoutP outside of the method where all rows are initialized, it will tell me:

对象引用未设置到对象的实例。

Object reference not set to the instance of an object.

我能做些什么?或任何其他方式来处理这种情况是有没有办法让一个方法中的方法(同时键入它听起来我意识到是多么愚蠢的)?

What can I do? Is there a way to get a method inside a method (I'm realising just how stupid that sounds while typing it) or any other way to deal with this Situation?

推荐答案

您是通过 GetRowHeights ittering(),返回每个行的高度。但你从 RowStyles 集合这是没有直接关系的第一个集合中删除。我认为 GetRowHeights()返回多行比 RowStyles

You are ittering through GetRowHeights(), returning the height of each row. But you are deleting from the RowStyles collection which is not directly related to the first collection. I assume that GetRowHeights() returns much more rows, than RowStyles has.

为什么不:

BibTable.RowCount = 0;
BibTable.RowStyles.Clear();

这篇关于为什么我不能在法达到的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆