【问题标题】:Unable to edit values in a DataGridView (using BindingList)无法编辑 DataGridView 中的值(使用 BindingList)
【发布时间】:2010-12-12 03:14:01
【问题描述】:

似乎由于未知原因,我现在无法在我的 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 是我之前提到的那个特殊属性。它没有设置功能,但按照this的说法,我应该是清楚的吧?

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

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

【问题讨论】:

    标签: c# .net-3.5 datagridview properties


    【解决方案1】:

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

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

    【讨论】:

    • 我刚刚遇到了同样的问题。吸取的教训:不要相信 VS Designer (VS2012)
    猜你喜欢
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多