private void FillPropertyGrid3() { string[] Languages = new string[] { "English", "Italian", "Spanish", "Dutch" }; MyOwnClass[] ListValues = new MyOwnClass[] { new MyOwnClass("English", 0), new MyOwnClass("Italian", 1), new MyOwnClass("Spanish", 2), new MyOwnClass("Dutch", 3) }; DataTable LookupTable = null; bool IsXmlSampleLoaded = false; document = new XmlDataDocument(); // Load a DataTable from XML ParseSchema(ref document, (new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.DirectoryPath + "\\books.xsd"); try { document.Load((new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase()).Info.DirectoryPath + "\\books.xml"); if (document.DataSet != null) { LookupTable = document.DataSet.Tables[1]; } if (LookupTable != null) { iCountRow = LookupTable.Rows.Count; IsXmlSampleLoaded = true; } } catch (Exception ex) { Console.WriteLine("Exception during XML Load: " + ex.Message); IsXmlSampleLoaded = false; } Properties.ShowCustomProperties = true; Properties.Item.Clear(); Properties.Item.Add("Array of objects", ListValues[2].Text, false, "Databinding", "This is a UITypeEditor that implement a listbox", true); Properties.Item[Properties.Item.Count - 1].ValueMember = "Value"; Properties.Item[Properties.Item.Count - 1].DisplayMember = "Text"; Properties.Item[Properties.Item.Count - 1].Datasource = ListValues; Properties.Item.Add("Array of strings", Languages[1], false, "Databinding", "This is a UITypeEditor that implement a listbox", true); Properties.Item[Properties.Item.Count - 1].Datasource = Languages; Properties.Item[Properties.Item.Count - 1].IsDropdownResizable = true; // If the XML Samples was loaded if (IsXmlSampleLoaded) { // Bind a property to a DataTable Properties.Item.Add("Datatable", "", false, "Databinding", "This is a UITypeEditor that implement a listbox", true); Properties.Item[Properties.Item.Count - 1].ValueMember = "book_Id"; Properties.Item[Properties.Item.Count - 1].DisplayMember = "title"; Properties.Item[Properties.Item.Count - 1].Datasource = LookupTable; } Properties.MoveSplitterTo(120); Properties.Refresh(); }
private void FillPropertyGrid1(FilterPropertyType filter) { string[] Languages = new string[] { "English", "Italian", "Spanish", "Dutch" }; MyOwnClass[] ListValues = new MyOwnClass[] { new MyOwnClass("English", 0), new MyOwnClass("Italian", 1), new MyOwnClass("Spanish", 2), new MyOwnClass("Dutch", 3) }; int[] Values = new int[] { 1, 2, 3, 4 }; MyOwnClass oInstance = new MyOwnClass("String value", 0); // The variable filter is used in the "Serialization Example" // The filter remove from the grid the properties not correctly supported // or not supported at all. Properties.ShowCustomProperties = true; Properties.Item.Clear(); // Simple properties Properties.Item.Add("My Integer", 100, false, "Simple properties", "This is an integer", true); Properties.Item.Add("My Double", 10.4, false, "Simple properties", "This is a double", true); Properties.Item.Add("My String", "My Value", false, "Simple properties", "This is a string", true); if (filter != FilterPropertyType.FilterXmlSerializer) { Properties.Item.Add("My Font", new Font("Arial", 9), false, "Simple properties", "This is a font class", true); Properties.Item.Add("My Color", new Color(), false, "Simple properties", "This is a color class", true); Properties.Item.Add("My Point", new Point(10, 10), false, "Simple properties", "This is point class", true); } Properties.Item.Add("My Date", new DateTime(DateAndTime.Today.Ticks), true, "Simple properties", "This is date class", true); Properties.Item.Add("My Enum", MyEnum.FirstEntry, false, "Simple properties", "Work with Enum too!", true); // IsPassword attribute Properties.Item.Add("My Password", "password", false, ".NET v2.0 only", "This is a masked string." + "\r\n" + "(This feature is available only under .NET v2.0)", true); Properties.Item[Properties.Item.Count - 1].IsPassword = true; // Filename editor Properties.Item.Add("Filename", "", false, "Properties with custom UITypeEditor", "This property is a filename path. It define a custom UITypeConverter that show a OpenFileDialog or a SaveFileDialog when the user press the 3 dots button to edit the value.", true); Properties.Item[Properties.Item.Count - 1].UseFileNameEditor = true; Properties.Item[Properties.Item.Count - 1].FileNameDialogType = UIFilenameEditor.FileDialogType.LoadFileDialog; Properties.Item[Properties.Item.Count - 1].FileNameFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { // Custom Editor Properties.Item.Add("My Custom Editor", "", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor(); // Custom Event Editor Properties.Item.Add("My Custom Event", "Click me", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].OnClick += this.CustomEventItem_OnClick; // Custom TypeConverter Properties.Item.Add("Integer", 1, false, "Properties with custom TypeConverter", "This property have a custom type converter that show a custom error message.", true); Properties.Item[Properties.Item.Count - 1].CustomTypeConverter = new MyTypeConverter(); } // Custom Choices Type Converter if (filter != FilterPropertyType.FilterXmlSerializer) { Properties.Item.Add("Language", "", false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true); Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Languages, true); Properties.Item.Add("Values", 1, false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true); Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Values, false); } if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { // Expandable Type Converter Properties.Item.Add("My object", oInstance, false, "Properties with custom TypeConverter", "This property make a \'MyOwnClass\' instance browsable.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; Properties.Item[Properties.Item.Count - 1].BrowsableLabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis; } // Dynamic properties if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { object grid = Properties; Properties.Item.Add("Autosize properties", ref grid, "AutoSizeProperties", false, "Dynamic Properties", "This is a dynamic bound property. It changes the autosize property of this grid. Try it!", true); Properties.Item.Add("Draw flat toolbar", ref grid, "DrawFlatToolbar", false, "Dynamic Properties", "This is a dynamic bound property. It changes the DrawFlatToolbar property of this grid. Try it!", true); object form = this; Properties.Item.Add("Form opacity", ref form, "Opacity", false, "Dynamic Properties", "This is a dynamic bound property. It changes the Opacity property of this form. Try it!", true); Properties.Item[Properties.Item.Count - 1].IsPercentage = true; // PropertyGridEx Properties.Item.Add("Item", ref grid, "Item", false, "PropertyGridEx", "Represent the PropertyGridEx Item collection.",true); Properties.Item[Properties.Item.Count - 1].Parenthesize = true; Properties.Item.Add("DocComment", ref grid, "DocComment", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; Properties.Item.Add("Image", ref grid, "DocCommentImage", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].DefaultValue = null; Properties.Item[Properties.Item.Count - 1].DefaultType = typeof(Image); Properties.Item.Add("Toolstrip", ref grid, "Toolstrip", false, "PropertyGridEx", "Represent the toolstrip of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; } if (filter == FilterPropertyType.FilterBinaryFormatter) { // Databinding works with serialization Properties.Item.Add("Array of objects", ListValues[2].Text, false, "Databinding", "This is a UITypeEditor that implement a listbox", true); Properties.Item[Properties.Item.Count - 1].ValueMember = "Value"; Properties.Item[Properties.Item.Count - 1].DisplayMember = "Text"; Properties.Item[Properties.Item.Count - 1].Datasource = ListValues; } Properties.Refresh(); }
private void FillPropertyGrid1(FilterPropertyType filter) { string[] Languages = new string[] { "English", "Italian", "Spanish", "Dutch" }; MyOwnClass[] ListValues = new MyOwnClass[] { new MyOwnClass("English", 0), new MyOwnClass("Italian", 1), new MyOwnClass("Spanish", 2), new MyOwnClass("Dutch", 3) }; int[] Values = new int[] { 1, 2, 3, 4 }; MyOwnClass oInstance = new MyOwnClass("String value", 0); // The variable filter is used in the "Serialization Example" // The filter remove from the grid the properties not correctly supported // or not supported at all. Properties.ShowCustomProperties = true; Properties.Item.Clear(); // Simple properties Properties.Item.Add("My Integer", 100, false, "Simple properties", "This is an integer", true); Properties.Item.Add("My Double", 10.4, false, "Simple properties", "This is a double", true); Properties.Item.Add("My String", "My Value", false, "Simple properties", "This is a string", true); if (filter != FilterPropertyType.FilterXmlSerializer) { Properties.Item.Add("My Font", new Font("Arial", 9), false, "Simple properties", "This is a font class", true); Properties.Item.Add("My Color", new Color(), false, "Simple properties", "This is a color class", true); Properties.Item.Add("My Point", new Point(10, 10), false, "Simple properties", "This is point class", true); } Properties.Item.Add("My Date", new DateTime(DateAndTime.Today.Ticks), true, "Simple properties", "This is date class", true); Properties.Item.Add("My Enum", MyEnum.FirstEntry, false, "Simple properties", "Work with Enum too!", true); // IsPassword attribute Properties.Item.Add("My Password", "password", false, ".NET v2.0 only", "This is a masked string." + "\r\n" + "(This feature is available only under .NET v2.0)", true); Properties.Item[Properties.Item.Count - 1].IsPassword = true; // Filename editor Properties.Item.Add("Filename", "", false, "Properties with custom UITypeEditor", "This property is a filename path. It define a custom UITypeConverter that show a OpenFileDialog or a SaveFileDialog when the user press the 3 dots button to edit the value.", true); Properties.Item[Properties.Item.Count - 1].UseFileNameEditor = true; Properties.Item[Properties.Item.Count - 1].FileNameDialogType = UIFilenameEditor.FileDialogType.LoadFileDialog; Properties.Item[Properties.Item.Count - 1].FileNameFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { // Custom Editor Properties.Item.Add("My Custom Editor", "", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor(); // Custom Event Editor Properties.Item.Add("My Custom Event", "Click me", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].OnClick += this.CustomEventItem_OnClick; // Custom TypeConverter Properties.Item.Add("Integer", 1, false, "Properties with custom TypeConverter", "This property have a custom type converter that show a custom error message.", true); Properties.Item[Properties.Item.Count - 1].CustomTypeConverter = new MyTypeConverter(); } // Custom Choices Type Converter if (filter != FilterPropertyType.FilterXmlSerializer) { Properties.Item.Add("Language", "", false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true); Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Languages, true); Properties.Item.Add("Values", 1, false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true); Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Values, false); } if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { // Expandable Type Converter Properties.Item.Add("My object", oInstance, false, "Properties with custom TypeConverter", "This property make a \'MyOwnClass\' instance browsable.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; Properties.Item[Properties.Item.Count - 1].BrowsableLabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis; } // Dynamic properties if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer) { object grid = Properties; Properties.Item.Add("Autosize properties", ref grid, "AutoSizeProperties", false, "Dynamic Properties", "This is a dynamic bound property. It changes the autosize property of this grid. Try it!", true); Properties.Item.Add("Draw flat toolbar", ref grid, "DrawFlatToolbar", false, "Dynamic Properties", "This is a dynamic bound property. It changes the DrawFlatToolbar property of this grid. Try it!", true); object form = this; Properties.Item.Add("Form opacity", ref form, "Opacity", false, "Dynamic Properties", "This is a dynamic bound property. It changes the Opacity property of this form. Try it!", true); Properties.Item[Properties.Item.Count - 1].IsPercentage = true; // PropertyGridEx Properties.Item.Add("Item", ref grid, "Item", false, "PropertyGridEx", "Represent the PropertyGridEx Item collection.", true); Properties.Item[Properties.Item.Count - 1].Parenthesize = true; Properties.Item.Add("DocComment", ref grid, "DocComment", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; Properties.Item.Add("Image", ref grid, "DocCommentImage", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].DefaultValue = null; Properties.Item[Properties.Item.Count - 1].DefaultType = typeof(Image); Properties.Item.Add("Toolstrip", ref grid, "Toolstrip", false, "PropertyGridEx", "Represent the toolstrip of the PropertyGrid.", true); Properties.Item[Properties.Item.Count - 1].IsBrowsable = true; } if (filter == FilterPropertyType.FilterBinaryFormatter) { // Databinding works with serialization Properties.Item.Add("Array of objects", ListValues[2].Text, false, "Databinding", "This is a UITypeEditor that implement a listbox", true); Properties.Item[Properties.Item.Count - 1].ValueMember = "Value"; Properties.Item[Properties.Item.Count - 1].DisplayMember = "Text"; Properties.Item[Properties.Item.Count - 1].Datasource = ListValues; } Properties.Refresh(); }