Consider following scenario:
DataGridView
named MyDataGridView
. MyDataGridView
in designer. AllowUserToAddRows
property of MyDataGridView
custom control to false
. MyDataGridView
instance in form. AllowUserToAddRows
property of the MyDataGridView
instance to true
. What I expect would happen: my instance should allow user to add rows. It doesn't. The moment I run build, the property of the instance is reset to the value set in MyDataGridView
definition.
So I'm obviously doing it wrong. How to do it right?
I want MyDataGridView
to have a different set of default values for properties than standard DataGridView
, but yet those properties should remain editable in application's designer. What is the most straightforward mean to achieve this?
Ok, here's one way of doing this, but it's terrible! I'm still looking for an easier way:
using System.ComponentModel;
using System.Windows.Forms;
namespace Test {
public partial class MyDataGridView : DataGridView {
bool _AllowUserToAddRows;
[Category("Behavior")]
[Description("Value indicating whether the option to add rows is displayed to the user")]
[DefaultValue(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public new bool AllowUserToAddRows {
get { return _AllowUserToAddRows; }
set { base.AllowUserToAddRows = _AllowUserToAddRows = value; } }
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.