Click here to Skip to main content
16,005,343 members
Home / Discussions / C#
   

C#

 
GeneralRe: urgent: question about update data using DataAdapter.Update Pin
Heath Stewart1-Oct-04 14:46
protectorHeath Stewart1-Oct-04 14:46 
GeneralRe: urgent: question about update data using DataAdapter.Update Pin
fox_chen2-Oct-04 9:53
fox_chen2-Oct-04 9:53 
Generalpropertygrid Pin
GoodQuestion1-Oct-04 11:44
GoodQuestion1-Oct-04 11:44 
GeneralRe: propertygrid Pin
Heath Stewart1-Oct-04 14:50
protectorHeath Stewart1-Oct-04 14:50 
GeneralRe: propertygrid Pin
Nick Parker2-Oct-04 9:57
protectorNick Parker2-Oct-04 9:57 
GeneralRe: propertygrid Pin
Alex Korchemniy2-Oct-04 10:27
Alex Korchemniy2-Oct-04 10:27 
GeneralRe: propertygrid Pin
GoodQuestion4-Oct-04 6:51
GoodQuestion4-Oct-04 6:51 
GeneralRe: propertygrid Pin
Heath Stewart4-Oct-04 7:52
protectorHeath Stewart4-Oct-04 7:52 
The problem is that the Type of the property warrants an editor, so you need to attribute your property (which takes precedence over the attribute on the property Type) with an editor that doesn't do anything:
using System;
using System.Drawing;
using System.Drawing.Design;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
 
public class Form1 : System.Windows.Forms.Form
{
  private System.Windows.Forms.PropertyGrid propertyGrid1;
  private System.Windows.Forms.RadioButton radioButton1;
  private CustomRadioButton radioButton2;
  private System.Windows.Forms.GroupBox groupBox1;
 
  public Form1()
  {
    InitializeComponent();
  }
 
  private void InitializeComponent()
  {
    this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
    this.radioButton1 = new System.Windows.Forms.RadioButton();
    this.radioButton2 = new CustomRadioButton();
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.groupBox1.SuspendLayout();
    this.SuspendLayout();
    // 
    // propertyGrid1
    // 
    this.propertyGrid1.CommandsVisibleIfAvailable = true;
    this.propertyGrid1.LargeButtons = false;
    this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
    this.propertyGrid1.Location = new System.Drawing.Point(8, 88);
    this.propertyGrid1.Name = "propertyGrid1";
    this.propertyGrid1.SelectedObject = this.radioButton1;
    this.propertyGrid1.Size = new System.Drawing.Size(280, 264);
    this.propertyGrid1.TabIndex = 0;
    this.propertyGrid1.Text = "propertyGrid1";
    this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
    this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
    // 
    // radioButton1
    // 
    this.radioButton1.Checked = true;
    this.radioButton1.Location = new System.Drawing.Point(8, 16);
    this.radioButton1.Name = "radioButton1";
    this.radioButton1.Size = new System.Drawing.Size(160, 24);
    this.radioButton1.TabIndex = 1;
    this.radioButton1.TabStop = true;
    this.radioButton1.Text = "BackgroundImage ...";
    this.radioButton1.CheckedChanged += new System.EventHandler(this.switchObject);
    // 
    // radioButton2
    // 
    this.radioButton2.Location = new System.Drawing.Point(8, 40);
    this.radioButton2.Name = "radioButton2";
    this.radioButton2.Size = new System.Drawing.Size(160, 24);
    this.radioButton2.TabIndex = 2;
    this.radioButton2.Text = "No BackgroundImage ...";
    this.radioButton2.CheckedChanged += new System.EventHandler(this.switchObject);
    // 
    // groupBox1
    // 
    this.groupBox1.Controls.Add(this.radioButton1);
    this.groupBox1.Controls.Add(this.radioButton2);
    this.groupBox1.Location = new System.Drawing.Point(8, 8);
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.Size = new System.Drawing.Size(280, 72);
    this.groupBox1.TabIndex = 3;
    this.groupBox1.TabStop = false;
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(296, 365);
    this.Controls.Add(this.groupBox1);
    this.Controls.Add(this.propertyGrid1);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
    this.MaximizeBox = false;
    this.Name = "Form1";
    this.Text = "Example";
    this.groupBox1.ResumeLayout(false);
    this.ResumeLayout(false);
 
  }
 
  [STAThread]
  static void Main() 
  {
    Application.Run(new Form1());
  }
 
  private void switchObject(object sender, System.EventArgs e)
  {
    RadioButton radio = sender as RadioButton;
    if (radio != null && radio.Checked) this.propertyGrid1.SelectedObject = radio;
  }
}
 
class CustomRadioButton : RadioButton
{
  [Editor(typeof(CustomRadioButtonImageEditor), typeof(UITypeEditor))]
  public override Image BackgroundImage
  {
    get
    {
      return base.BackgroundImage;
    }
    set
    {
      base.BackgroundImage = value;
    }
  }
 
  class CustomRadioButtonImageEditor : UITypeEditor
  {
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
      return UITypeEditorEditStyle.None;
    }
  }
}
Pay attention to the BackgroundImage property in the PropertyGrid when selecting the different options.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: propertygrid Pin
GoodQuestion5-Oct-04 11:44
GoodQuestion5-Oct-04 11:44 
GeneralRe: propertygrid Pin
Heath Stewart5-Oct-04 12:25
protectorHeath Stewart5-Oct-04 12:25 
GeneralRe: propertygrid Pin
GoodQuestion6-Oct-04 12:46
GoodQuestion6-Oct-04 12:46 
GeneralRe: propertygrid Pin
Heath Stewart6-Oct-04 14:48
protectorHeath Stewart6-Oct-04 14:48 
GeneralStored Procedures - SQL Database Pin
pat2708811-Oct-04 11:32
pat2708811-Oct-04 11:32 
GeneralRe: Stored Procedures - SQL Database Pin
Colin Angus Mackay1-Oct-04 14:39
Colin Angus Mackay1-Oct-04 14:39 
GeneralRe: Stored Procedures - SQL Database Pin
pat2708811-Oct-04 21:23
pat2708811-Oct-04 21:23 
GeneralIIS Error Pin
pat2708811-Oct-04 11:32
pat2708811-Oct-04 11:32 
GeneralRe: IIS Error Pin
Heath Stewart1-Oct-04 14:52
protectorHeath Stewart1-Oct-04 14:52 
GeneralRe: IIS Error Pin
pat2708811-Oct-04 21:42
pat2708811-Oct-04 21:42 
GeneralRe: IIS Error Pin
Heath Stewart2-Oct-04 4:55
protectorHeath Stewart2-Oct-04 4:55 
QuestionRichTextBox the best way? Pin
vista271-Oct-04 11:17
vista271-Oct-04 11:17 
Questionbest regex mail pattern ? Pin
cemlouis1-Oct-04 10:00
cemlouis1-Oct-04 10:00 
AnswerRe: best regex mail pattern ? Pin
Brian Nottingham1-Oct-04 10:13
Brian Nottingham1-Oct-04 10:13 
AnswerRe: best regex mail pattern ? Pin
Heath Stewart1-Oct-04 14:57
protectorHeath Stewart1-Oct-04 14:57 
GeneralRe: best regex mail pattern ? Pin
Brian Nottingham1-Oct-04 20:02
Brian Nottingham1-Oct-04 20:02 
GeneralRe: best regex mail pattern ? Pin
leppie1-Oct-04 22:00
leppie1-Oct-04 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.