无法编辑 DataGridView 中的值(使用 BindingList)

发布于 2024-10-07 04:48:38 字数 2880 浏览 0 评论 0原文

看来,由于未知原因,我现在无法编辑 DataGridView 中的任何内容。 DGV 的 ReadOnly 属性值为 false,并且除一列之外的所有列的 ReadOnly 属性也都设置为 false。

我开始认为这可能是由于我尝试添加到我的一个类中的特殊值,我只想在类中修改该值,但仍然只对公众只读。我不认为该值会干扰其他任何内容,但尽管如此,这里是我的代码的相关部分:

        private void loaderWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        loadingBar.Value = e.ProgressPercentage;
        if (e.UserState != null)
        {
            savefiles.Add((SaveFile)e.UserState);
        }
    }

其中 savefiles 是 BindingList,SaveFile 是我的类:

public class SaveFile
{
    private string d_directory;
    private int d_weirdnumber;
    private bool d_isautosave;
    private string d_fullname;
    private string d_datatype;
    private string d_owner;
    private bool d_isquicksave;
    private string d_title;
    private string d_gametime;

    public SaveFile() { }

    public SaveFile(string directory, int weirdnumber, bool isautosave, string fullname, string datatype, string owner, bool isquicksave, string title)
    {
        d_directory = directory;
        d_weirdnumber = weirdnumber;
        d_isautosave = isautosave;
        d_fullname = fullname;
        d_datatype = datatype;
        d_owner = owner;
        d_isquicksave = isquicksave;
        d_title = title;
    }

    public string Gametime
    {
        get { return d_gametime; }
    }

    public string Datatype
    {
        get { return d_datatype; }
        set { d_datatype = value; }
    }

    public string Title
    {
        get { return d_title; }
        set { d_title = value; }
    }

    public bool IsQuickSave
    {
        get { return d_isquicksave; }
        set { d_isquicksave = value; }
    }

    public bool IsAutoSave
    {
        get { return d_isautosave; }
        set { d_isautosave = value; }
    }

    public string Directory
    {
        get { return d_directory; }
        set { d_directory = value; }
    }

    public string FullName
    {
        get { return d_fullname; }
        set
        {
            d_fullname = value;
            string[] split = value.Split(new char[]{'-'});
            foreach (string str in split)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(str, "^\\d\\d:\\d\\d:\\d\\d$"))
                {
                    d_gametime = str;
                }
            }
        }
    }

    public int Weirdnumber
    {
        get { return d_weirdnumber; }
        set { d_weirdnumber = value; }
    }

    public string Owner
    {
        get { return d_owner; }
        set { d_owner = value; }
    }
}

Gametime 是我之前提到的特殊属性。它没有设置功能,但根据 这个,我应该清楚了吧?

谁能告诉我为什么我无法编辑任何 DGV 单元格?

编辑:我刚刚发现将 AutoGenerateColumns 设置为 false 可以让我再次编辑,但我仍然不知道为什么。

It seems that, due to an unknown cause, I am now unable to edit anything in my DataGridView. The DGV's ReadOnly property value is false, and all columns except for one all have the ReadOnly property set to false as well.

I'm beginning to think that it may be due to a special value I tried adding to one of my classes, one that I only wanted to be modified within the class, but still read only to the public. I don't think that value is messing with anything else, but none the less, here is the relevant portion of my code:

        private void loaderWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        loadingBar.Value = e.ProgressPercentage;
        if (e.UserState != null)
        {
            savefiles.Add((SaveFile)e.UserState);
        }
    }

Where savefiles is a BindingList, and where SaveFile is my class:

public class SaveFile
{
    private string d_directory;
    private int d_weirdnumber;
    private bool d_isautosave;
    private string d_fullname;
    private string d_datatype;
    private string d_owner;
    private bool d_isquicksave;
    private string d_title;
    private string d_gametime;

    public SaveFile() { }

    public SaveFile(string directory, int weirdnumber, bool isautosave, string fullname, string datatype, string owner, bool isquicksave, string title)
    {
        d_directory = directory;
        d_weirdnumber = weirdnumber;
        d_isautosave = isautosave;
        d_fullname = fullname;
        d_datatype = datatype;
        d_owner = owner;
        d_isquicksave = isquicksave;
        d_title = title;
    }

    public string Gametime
    {
        get { return d_gametime; }
    }

    public string Datatype
    {
        get { return d_datatype; }
        set { d_datatype = value; }
    }

    public string Title
    {
        get { return d_title; }
        set { d_title = value; }
    }

    public bool IsQuickSave
    {
        get { return d_isquicksave; }
        set { d_isquicksave = value; }
    }

    public bool IsAutoSave
    {
        get { return d_isautosave; }
        set { d_isautosave = value; }
    }

    public string Directory
    {
        get { return d_directory; }
        set { d_directory = value; }
    }

    public string FullName
    {
        get { return d_fullname; }
        set
        {
            d_fullname = value;
            string[] split = value.Split(new char[]{'-'});
            foreach (string str in split)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(str, "^\\d\\d:\\d\\d:\\d\\d$"))
                {
                    d_gametime = str;
                }
            }
        }
    }

    public int Weirdnumber
    {
        get { return d_weirdnumber; }
        set { d_weirdnumber = value; }
    }

    public string Owner
    {
        get { return d_owner; }
        set { d_owner = value; }
    }
}

Gametime is that special property I mentioned earlier. It doesn't have a set function, but according to this, I should be in the clear, right?

Can anyone then tell me why I may not be able to edit any of the DGV cells?

EDIT: I just found out that not setting AutoGenerateColumns to false allows me to edit again, but I still don't know why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-10-14 04:48:38

几个小时后,一位朋友终于通过远程桌面查看了它。他编写了一个函数来强制所有列都具有非只读状态,结果发现,它起作用了。因此,我们查看了编辑器中的列属性,不知何故……我不知道为什么……它们都设置为只读。我发誓我之前已经检查过四次了。

这个故事的教训(我猜):如有疑问,请检查您的设置。当不怀疑时,就变得怀疑。否则,请向 Microsoft 提交错误报告:\

After several hours, a friend finally took a look at it over Remote Desktop. He wrote a function to force all columns to have a non read-only status, and go figure, it worked. So we looked at the column properties in the editor, and somehow... I don't know why... they were all set to Read only. I swear I checked them 4 times before.

The lesson of this story (I guess): When in doubt, check your settings. When not in doubt, become doubtful. Otherwise, file a bug report to Microsoft :\

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文