开发者

Making Custom DataGridViewCell ReadOnly

开发者 https://www.devze.com 2022-12-29 16:21 出处:网络
I am making several custom DataGridViewCell classes to handle various cases in my C# application.One of the custom classes is associated with read-only data, so I\'m attempting to make the cell itself

I am making several custom DataGridViewCell classes to handle various cases in my C# application. One of the custom classes is associated with read-only data, so I'm attempting to make the cell itself read-only.

I initially tried setting the ReadOnly property in the constructor, but doing so causes an InvalidOperationException: "ReadOnly property of a cell cannot be set before it is added to a row."

Which method should I override (i.e., which method add开发者_如何转开发s the cell to the row), so that I can set the ReadOnly property?


It looks like the way to get the desired behavior (prohibiting the user from editing the data in the cell) is to override the EditType property in the DataGridViewCell sub-class:

    public override Type EditType
    {
        get
        {
            return null;
        }
    }

This keeps the cell from displaying an edit control, consequently making the cell read-only.

0

精彩评论

暂无评论...
验证码 换一张
取 消