I have a property grid on my app and I have created the following class for it:
class NginXConfig
{
[Browsable(true)]
[ReadOnly(true)]
[Category("General")]
[Description("Defines the number of worker processes. Windows only supports one.")]
int _worker_processes = 1;
public int worker_processes
{
get { return _worker_processes; }
set { _worker_processes = value; }
}
[Browsable(true)]
[ReadOnly(false)]
[Category("General")]
[Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
int _worker_rlimit_nofile = 100000;
public int worker_rlimit_nofile
{
get { return _worker_rlimit_nofile; }
set { _worker_rlimit_nofile = value; }
}
[Browsable(true)]
[ReadOnly(false)]
[Category("General")]
[Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
string _error_log_level = "crit";
public string error_log_level
{
get { return _error_log_level; }
set { _error_log_level = value; }
}
}
On the property grid, when I set the SelectedObject
- it renders like this:
The category I have defined as "General" is not showing. It's showing as "Misc".
The hint Description
is not showing.
Is it possible to define the order in which these fields show on my property grid via the class?
This issue is now solved. Here's the working version of my class:
class NginXConfig
{
[Browsable(true), ReadOnly(true), Category("General"), DefaultValueAttribute(1), Description("Defines the number of worker processes. Windows operating system supports only one.")]
public int worker_processes { get ; set; }
[Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute(10000), Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
public int worker_rlimit_nofile { get; set; }
[Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute("crit"), Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
public string error_log_level { get; set; }
public NginXConfig()
{
worker_processes = 1;
worker_rlimit_nofile = 10000;
error_log_level = "crit";
}
}
Define in this way:
int _worker_processes = 1;
[Browsable(true),ReadOnly(true),Category("General"),Description("Defines the number of worker processes. Windows only supports one.")]
public int worker_processes
{
get { return _worker_processes; }
set { _worker_processes = value; }
}
The attributes are for property, not for private variable. And why not { get; set; }
without int _worker_processes = 1;
.