├── Media ├── img_01.png ├── wiki_img_01.png ├── wiki_img_02.png ├── wiki_img_03.png ├── wiki_img_04.png ├── wiki_img_05.png └── wiki_img_06.png ├── Examples ├── Database │ ├── daoDataSet.xsc │ ├── daoDataSet.xss │ ├── daoDataSet.cs │ └── daoDataSet.xsd ├── app.config ├── Program.cs ├── Properties │ ├── Settings.settings │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── ExamplesForms │ ├── Example1Form.cs │ ├── Example1Form.resx │ └── Example1Form.Designer.cs ├── Examples.csproj ├── MainForm.cs └── MainForm.resx ├── Source ├── DataDescriptors │ ├── United.cs │ ├── FieldGroupDescriptor.cs │ ├── ColumnDescriptor.cs │ └── FieldDescriptor.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Extenders │ ├── Settings.cs │ ├── FlowLayoutPanel │ │ └── GroupsGenerator.cs │ └── DataGridView │ │ ├── Drawing.cs │ │ ├── ColumnStyles.cs │ │ ├── Preparations.cs │ │ └── ColumnsGenerator.cs ├── Forms │ ├── FormServices.cs │ ├── BitMaskCheckedListBox.cs │ ├── SortableBindingList.cs │ ├── PromptedTextBox.cs │ ├── RowFilterBuilder.cs │ ├── HeaderTableLayoutPanel.cs │ └── SelectItemForm.cs └── DataViewExtenders.csproj ├── LICENSE ├── DataViewExtenders.sln ├── README.md └── .gitignore /Media/img_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/img_01.png -------------------------------------------------------------------------------- /Media/wiki_img_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_01.png -------------------------------------------------------------------------------- /Media/wiki_img_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_02.png -------------------------------------------------------------------------------- /Media/wiki_img_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_03.png -------------------------------------------------------------------------------- /Media/wiki_img_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_04.png -------------------------------------------------------------------------------- /Media/wiki_img_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_05.png -------------------------------------------------------------------------------- /Media/wiki_img_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datarza/DataViewExtenders/HEAD/Media/wiki_img_06.png -------------------------------------------------------------------------------- /Examples/Database/daoDataSet.xsc: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace Examples 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// The main entry point for the application. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new MainForm()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/DataDescriptors/United.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CBComponents.DataDescriptors 5 | { 6 | /// 7 | /// Data visualization style 8 | /// 9 | public enum EditorDataStyle 10 | { 11 | Decimal, Number, Money, Percent, DateTime, Date 12 | } 13 | 14 | /// 15 | /// Delegate of getting data method for EditorColumnMode.ListBox 16 | /// 17 | /// 18 | public delegate object GetListBoxItemsDelegate(); 19 | 20 | /// 21 | /// Delegate of format data method 22 | /// 23 | /// 24 | /// 25 | /// 26 | public delegate object FormatValueDelegate(object DataBoundItem, string DataPropertyName); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <?xml version="1.0" encoding="utf-16"?> 7 | <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 8 | <ConnectionString>Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True</ConnectionString> 9 | <ProviderName>System.Data.SqlClient</ProviderName> 10 | </SerializableConnectionString> 11 | Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True 12 | 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Radu Martin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Examples/Database/daoDataSet.xss: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 379 17 | 224 18 | 19 | 20 | 645 21 | 224 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /DataViewExtenders.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataViewExtenders", "Source\DataViewExtenders.csproj", "{FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{5981795B-49A3-4816-B886-B0A18626FE57}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {5981795B-49A3-4816-B886-B0A18626FE57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {5981795B-49A3-4816-B886-B0A18626FE57}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {5981795B-49A3-4816-B886-B0A18626FE57}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {5981795B-49A3-4816-B886-B0A18626FE57}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Examples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DataViewExtendersExamples")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Examples for DataViewExtenders")] 13 | [assembly: AssemblyCopyright("Copyright © Radu Martin, 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5981795b-49a3-4816-b886-b0a18626fe57")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DataViewExtenders")] 9 | [assembly: AssemblyDescription("Extenders for WinForms controls, such as DataGridView, BindingSource, BindingNavigator and so on")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DataViewExtenders")] 13 | [assembly: AssemblyCopyright("Copyright © Radu Martin, 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ffe9bbb5-8b9b-40ea-9499-aa2de0ecb1f6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/DataDescriptors/FieldGroupDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CBComponents.DataDescriptors 5 | { 6 | /// 7 | /// Width size of column or field 8 | /// 9 | public enum DataDescriptorSizeWidth : int 10 | { 11 | Smaller = 45, 12 | Small = 90, 13 | Medium = 135, 14 | Normal = 225, 15 | Large = 320, 16 | Larger = 360 17 | } 18 | 19 | /// 20 | /// DataDescriptor of groups on the Panel 21 | /// 22 | public class GroupDataDescriptor 23 | { 24 | public string CaptionText { get; set; } 25 | 26 | public FieldDataDescriptor[] Fields { get; set; } 27 | 28 | private const int _defaultSizeWidth = (int)DataDescriptorSizeWidth.Smaller / 2; 29 | 30 | public GroupDataDescriptor(string CaptionText, int SizeWidth, params FieldDataDescriptor[] Fields) 31 | { 32 | this.CaptionText = CaptionText; 33 | if (SizeWidth > _defaultSizeWidth) 34 | foreach (var field in Fields) 35 | if (!field.SizeWidth.HasValue) 36 | field.SizeWidth = SizeWidth; 37 | this.Fields = Fields; 38 | } 39 | 40 | public GroupDataDescriptor(string CaptionText, DataDescriptorSizeWidth SizeWidth, params FieldDataDescriptor[] Fields) 41 | : this(CaptionText, (int)SizeWidth, Fields) { } 42 | 43 | public GroupDataDescriptor(string CaptionText, params FieldDataDescriptor[] Fields) 44 | : this(CaptionText, _defaultSizeWidth, Fields) { } 45 | 46 | /// 47 | /// Resulted Panel after generation 48 | /// 49 | public System.Windows.Forms.Panel GeneratedPanel = null; 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Source/Extenders/Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows.Forms; 4 | 5 | namespace CBComponents 6 | { 7 | public static class Settings 8 | { 9 | /// 10 | /// Setting the main form of the application that is used for showing Dialogs and Information forms 11 | /// 12 | /// the main form 13 | public static void SetMainForm(IWin32Window MainWindow) 14 | { 15 | FormServices.MainWindow = MainWindow; 16 | } 17 | 18 | /// 19 | /// Images that is used for generating 20 | /// 21 | public static class Images 22 | { 23 | private static Bitmap selectRowImage = Properties.Resources.SelectRowImage; 24 | public static Bitmap SelectRowImage 25 | { 26 | get { return Images.selectRowImage; } 27 | set { if (value != null) Images.selectRowImage = value; } 28 | } 29 | 30 | private static Bitmap clearFieldImage = Properties.Resources.ClearFieldImage; 31 | public static Bitmap ClearFieldImage 32 | { 33 | get { return Images.clearFieldImage; } 34 | set { if (value != null) Images.clearFieldImage = value; } 35 | } 36 | } 37 | 38 | /// 39 | /// Settings for generation HeaderTableLayoutPanel on the panels 40 | /// 41 | public static class HeaderTableLayoutPanel 42 | { 43 | public static CBComponents.HeaderTableLayoutPanel.HighlightCaptionStyle CaptionStyle { get; set; } = CBComponents.HeaderTableLayoutPanel.HighlightCaptionStyle.NavisionAxaptaStyle; 44 | public static byte CaptionLineWidth { get; set; } = 2; 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Examples/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Examples.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] 29 | [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Database.mdf;" + 30 | "Integrated Security=True")] 31 | public string DatabaseConnectionString { 32 | get { 33 | return ((string)(this["DatabaseConnectionString"])); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Examples/ExamplesForms/Example1Form.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace Examples 11 | { 12 | public partial class Example1Form : Form 13 | { 14 | public const string TextName = "BitMaskCheckedListBox example"; 15 | 16 | public Example1Form() 17 | { 18 | InitializeComponent(); 19 | this.Text = Example1Form.TextName; 20 | 21 | long j = 1; 22 | for (int i = 0; i < 201; i++) 23 | { 24 | if (i<32) this.bmclBox.Items.Add(string.Format("{0,2:D2} - {1}", i + 1, j)); 25 | else if (i < 64) this.bmclBox.Items.Add(string.Format("{0,2:D2}", i + 1)); 26 | else this.bmclBox.Items.Add(string.Format("+{0,2:D3}", i + 1)); 27 | j = j * 2; 28 | } 29 | 30 | this.textBoxValue.DataBindings.Add("Text", this.bmclBox, "Value", false, DataSourceUpdateMode.OnPropertyChanged); 31 | this.textBoxLongValue.DataBindings.Add("Text", this.bmclBox, "LongValue", false, DataSourceUpdateMode.OnPropertyChanged); 32 | this.bmclBox.SelectedValueChanged += BmclBox_SelectedValueChanged; 33 | 34 | this.bmclBox.Value = 54613; 35 | this.BmclBox_SelectedValueChanged(this, EventArgs.Empty); 36 | } 37 | 38 | private void BmclBox_SelectedValueChanged(object sender, EventArgs e) 39 | { 40 | var items = this.bmclBox.GetValues(); 41 | string result = string.Empty; 42 | for (int i = 0; i < items.Length; i++) 43 | if (items[i]) 44 | result += string.Format("{0,2:D2}, ", i + 1); 45 | if (!string.IsNullOrEmpty(result)) result = result.Remove(result.Length - 2); 46 | this.textBoxValues.Text = result; 47 | } 48 | 49 | private void ExamplesForm_Load(object sender, EventArgs e) 50 | { 51 | 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DataViewExtenders 2 | 3 | These extenders can generate data-bound columns in the DataGridView, can make data-bound controls in the FlowLayoutPanel and can group generated controls on the TableLayoutPanel. Moreover, extenders implement additional functionality for DataGridView, DataGridViewColumn, FlowLayoutPanel, TableLayoutPanel and provide several WinForms control. 4 | 5 | ![Preview](Media/img_01.png) 6 | 7 | ## Features for DataGridView and DataGridViewColumn 8 | 9 | - DataRowState visualization in the RowHeaders for the changed and inserted rows 10 | - Visualization styles for DataGridViewColumns in a number of different ways 11 | - Preparation the DataGridView for showing data, editing data and reports 12 | - Tuned and auto generated columns by DataType and preferences 13 | - Special patern for lists 14 | ...and much more 15 | 16 | Please, read [DataGridView Wiki](../../wiki/DataGridView) and [DataGridViewColumn Wiki](../../wiki/DataGridViewColumn) for detail information. 17 | 18 | ## Features for FlowLayoutPanel and TableLayoutPanel 19 | 20 | - Panel with the grouping function 21 | - TableLayoutPanel provides highlighted header 22 | - Tuned and auto generated fields by DataType and preferences 23 | - Special patern for nullable types and lists 24 | ...and much more 25 | 26 | Please, read [FlowLayoutPanel Wiki](../../wiki/FlowLayoutPanel) and [TableLayoutPanel Wiki](../../wiki/TableLayoutPanel) for detail information. 27 | 28 | ## Credits 29 | 30 | - [Farm-Fresh Web Icons](http://www.fatcow.com/free-icons) have been used in examples. 31 | - [C# TextBox with Outlook 2007-style prompt](https://www.codeproject.com/Articles/15954/C-TextBox-with-Outlook-style-prompt) has been used in developing. 32 | - Idea and source code from [Support filtering and searching on multiple columns with RowFilterBuilder](https://www.codeproject.com/Articles/14640/Support-filtering-and-searching-on-multiple-column) have been used in developing. 33 | 34 | ## Contacts 35 | 36 | I would appreciate hearing your opinion on this. If you have any questions, please feel free to contact me by email: [radu.martin@hotmail.com](mailto://radu.martin@hotmail.com) 37 | -------------------------------------------------------------------------------- /Source/Forms/FormServices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | 5 | namespace CBComponents 6 | { 7 | internal static partial class FormServices 8 | { 9 | /// 10 | /// The main form of the application 11 | /// 12 | internal static IWin32Window MainWindow = null; 13 | 14 | internal static DialogResult ShowFormDialog(Form form) 15 | { 16 | if (FormServices.MainWindow == null) return form.ShowDialog(); 17 | else return form.ShowDialog(FormServices.MainWindow); 18 | } 19 | 20 | internal static void ShowMessage(string Message) 21 | { 22 | if (FormServices.MainWindow == null) MessageBox.Show(Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); 23 | else MessageBox.Show(FormServices.MainWindow, Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); 24 | } 25 | 26 | internal static void ShowError(string ErrorMessage, bool IsWarning = false) 27 | { 28 | if (FormServices.MainWindow == null) MessageBox.Show(ErrorMessage, IsWarning ? "Warning" : "Error", MessageBoxButtons.OK, IsWarning ? MessageBoxIcon.Warning : MessageBoxIcon.Error); 29 | else MessageBox.Show(FormServices.MainWindow, ErrorMessage, IsWarning ? "Warning" : "Error", MessageBoxButtons.OK, IsWarning ? MessageBoxIcon.Warning : MessageBoxIcon.Error); 30 | } 31 | 32 | internal static void ShowError(Exception ex) 33 | { 34 | if (FormServices.MainWindow == null) MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); 35 | else MessageBox.Show(FormServices.MainWindow, ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); 36 | } 37 | 38 | internal static bool ShowWarning(string Message) 39 | { 40 | if (FormServices.MainWindow == null) return MessageBox.Show(Message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes; 41 | else return MessageBox.Show(FormServices.MainWindow, Message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes; 42 | } 43 | 44 | internal static bool ShowWarning(string Caption, string Message) 45 | { 46 | if (FormServices.MainWindow == null) return MessageBox.Show(Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes; 47 | else return MessageBox.Show(FormServices.MainWindow, Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes; 48 | } 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /Source/Extenders/FlowLayoutPanel/GroupsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // DataViewExtenders 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | using CBComponents.DataDescriptors; 20 | using CBComponents.Forms; 21 | 22 | public static partial class FlowLayoutPanelExtenders 23 | { 24 | /// 25 | /// Group generator that works on group and field data descriptions (GroupDataDescriptor & FieldDataDescriptor) 26 | /// 27 | /// FlowLayoutPanel 28 | /// Data Source to support data-binding 29 | /// Field data descriptors 30 | public static void GenerateGroups(this FlowLayoutPanel groupPanel, object DataSource, params GroupDataDescriptor[] Groups) 31 | { 32 | FlowLayoutPanelExtenders.GenerateGroups(groupPanel, null, DataSource, Groups); 33 | } 34 | 35 | /// 36 | /// Group generator that works on group and field data descriptions (GroupDataDescriptor & FieldDataDescriptor) 37 | /// 38 | /// FlowLayoutPanel 39 | /// ToolTip 40 | /// Data Source to support data-binding 41 | /// Group data descriptors and Field data descriptors 42 | public static void GenerateGroups(this FlowLayoutPanel groupPanel, ToolTip toolTip, object DataSource, params GroupDataDescriptor[] Groups) 43 | { 44 | groupPanel.SuspendLayout(); 45 | groupPanel.Controls.Clear(); 46 | if (DataSource == null || Groups == null || Groups.Length == 0) return; 47 | foreach (var group in Groups) 48 | { 49 | var dataPanel = new HeaderTableLayoutPanel(); // TableLayoutPanel(); 50 | group.GeneratedPanel = dataPanel; 51 | dataPanel.CaptionText = group.CaptionText; 52 | dataPanel.CaptionStyle = Settings.HeaderTableLayoutPanel.CaptionStyle; 53 | dataPanel.CaptionLineWidth = Settings.HeaderTableLayoutPanel.CaptionLineWidth; 54 | dataPanel.GenerateFields(toolTip, DataSource, group.Fields); 55 | groupPanel.Controls.Add(dataPanel); 56 | } 57 | groupPanel.ResumeLayout(false); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/DataDescriptors/ColumnDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CBComponents.DataDescriptors 5 | { 6 | /// 7 | /// Editor mode of columns on the GridView 8 | /// 9 | public enum ColumnEditorMode 10 | { 11 | Auto, 12 | TextBox, 13 | CheckBox, 14 | ComboBox, ListBox 15 | } 16 | 17 | /// 18 | /// DataDescriptor of columns on the GridView 19 | /// 20 | public class ColumnDataDescriptor 21 | { 22 | public string HeaderText { get; set; } 23 | public string ColumnName { get; set; } 24 | public ColumnEditorMode Mode { get; set; } 25 | public EditorDataStyle? Style { get; set; } 26 | public bool IsNull { get; set; } 27 | public object NullValue { get; set; } 28 | public bool IsReadOnly { get; set; } 29 | public int? MaxLength { get; set; } 30 | public float? FillWeight { get; set; } 31 | public object DataSource { get; set; } 32 | public string ValueMember { get; set; } 33 | public string DisplayMember { get; set; } 34 | public GetListBoxItemsDelegate GetListBoxItemsMethod { get; set; } 35 | public FormatValueDelegate FormatValueMethod { get; set; } 36 | public ColumnDataDescriptor(string HeaderText, DataColumn Column, ColumnEditorMode Mode = ColumnEditorMode.Auto, 37 | EditorDataStyle? Style = null, float? FillWeight = null, object NullValue = null, bool IsReadOnly = false, 38 | object DataSource = null, string ValueMember = null, string DisplayMember = null, 39 | GetListBoxItemsDelegate GetListBoxItemsMethod = null, 40 | FormatValueDelegate FormatValueMethod = null) 41 | { 42 | if (Mode == ColumnEditorMode.Auto) 43 | { 44 | if (DataSource != null && ValueMember != null && DisplayMember != null && GetListBoxItemsMethod != null) Mode = ColumnEditorMode.ListBox; 45 | else if (ValueMember != null && GetListBoxItemsMethod != null && FormatValueMethod != null) Mode = ColumnEditorMode.ListBox; 46 | else if (DataSource != null && ValueMember != null && DisplayMember != null) Mode = ColumnEditorMode.ComboBox; 47 | else if (FormatValueMethod != null) { Mode = ColumnEditorMode.TextBox; this.IsReadOnly = true; } 48 | else if (Column.DataType == typeof(bool)) Mode = ColumnEditorMode.CheckBox; 49 | else if (Column.DataType == typeof(Guid)) { Mode = ColumnEditorMode.TextBox; this.IsReadOnly = true; } 50 | else Mode = ColumnEditorMode.TextBox; 51 | } 52 | this.HeaderText = HeaderText; // Column.Caption; 53 | this.ColumnName = Column.ColumnName; 54 | this.Mode = Mode; 55 | this.Style = Style; 56 | this.IsNull = Column.AllowDBNull; 57 | this.NullValue = NullValue; 58 | this.IsReadOnly = this.IsReadOnly || Column.ReadOnly || IsReadOnly; 59 | if (Column.MaxLength > 0) this.MaxLength = Column.MaxLength; 60 | this.FillWeight = FillWeight; 61 | this.DataSource = DataSource; 62 | this.ValueMember = ValueMember; 63 | this.DisplayMember = DisplayMember; 64 | this.GetListBoxItemsMethod = GetListBoxItemsMethod; 65 | this.FormatValueMethod = FormatValueMethod; 66 | } 67 | /// 68 | /// Resulted Column after generation 69 | /// 70 | public System.Windows.Forms.DataGridViewColumn GeneratedDataGridViewColumn = null; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Source/Extenders/DataGridView/Drawing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // DataViewExtenders 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | using CBComponents.DataDescriptors; 20 | using CBComponents.Forms; 21 | 22 | public static partial class DataGridViewExtenders 23 | { 24 | /// 25 | /// Adding a drawing in the RowHeaders for the changed or inserted rows 26 | /// based on yellow colors with gradient 27 | /// 28 | /// DataGridView 29 | public static void AddDataRowStateDrawingInRowHeaders(this DataGridView dataGrid) 30 | { 31 | DataGridViewExtenders.AddDataRowStateDrawingInRowHeaders(dataGrid, 32 | Color.FromArgb(0x99, 0xFF, 0xCC, 0x33), 33 | Color.FromArgb(0x99, 0xFF, 0x66, 0x00), 34 | true); 35 | } 36 | 37 | /// 38 | /// Adding a drawing in the RowHeaders for the changed or inserted rows 39 | /// based on prefered color with gradient 40 | /// 41 | /// DataGridView 42 | /// Color for inserted and changed rows 43 | public static void AddDataRowStateDrawingInRowHeaders(this DataGridView dataGrid, Color preferedColor) 44 | { 45 | DataGridViewExtenders.AddDataRowStateDrawingInRowHeaders(dataGrid, 46 | preferedColor, 47 | preferedColor, 48 | true); 49 | } 50 | 51 | /// 52 | /// Adding a drawing in the RowHeaders for the changed or inserted rows 53 | /// 54 | /// DataGridView 55 | /// Color for changed rows or null for using the default yellow color 56 | /// Color for inserted rows or null for using the default yellow-red color 57 | public static void AddDataRowStateDrawingInRowHeaders(this DataGridView dataGrid, Color chgColor, Color insColor, bool IsGradient) 58 | { 59 | // drawing the RowHeader 60 | dataGrid.CellPainting += delegate (object sender, DataGridViewCellPaintingEventArgs e) 61 | { 62 | if (dataGrid.RowHeadersVisible) 63 | if (e.ColumnIndex == -1 && e.RowIndex >= 0) 64 | { 65 | var dbItem = dataGrid.Rows[e.RowIndex].DataBoundItem as DataRowView; 66 | if (dbItem != null) 67 | { 68 | var rowState = dbItem.Row.RowState; 69 | if (rowState == DataRowState.Added || rowState == DataRowState.Modified) 70 | { 71 | Color _color = rowState == DataRowState.Modified ? chgColor : insColor; 72 | Brush _brush; 73 | if (IsGradient) _brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.CellBounds, Color.Transparent, _color, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); 74 | else _brush = new SolidBrush(_color); 75 | e.Paint(e.ClipBounds, DataGridViewPaintParts.Background); 76 | e.Graphics.FillRectangle(_brush, e.CellBounds); 77 | e.Paint(e.ClipBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.Background); 78 | e.Handled = true; 79 | } 80 | } 81 | } 82 | }; 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Source/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CBComponents.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CBComponents.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap ClearFieldImage { 67 | get { 68 | object obj = ResourceManager.GetObject("ClearFieldImage", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap SelectRowImage { 77 | get { 78 | object obj = ResourceManager.GetObject("SelectRowImage", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Source/Forms/BitMaskCheckedListBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // BitMaskCheckedListBox 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | [ToolboxBitmap(typeof(CheckedListBox))] 20 | public class BitMaskCheckedListBox : CheckedListBox 21 | { 22 | public BitMaskCheckedListBox() 23 | { 24 | this.CheckOnClick = true; 25 | /*this.ItemCheck += (sender, e) => 26 | { 27 | this.ValueChanged?.Invoke(sender, EventArgs.Empty); 28 | this.LongValueChanged?.Invoke(sender, EventArgs.Empty); 29 | };*/ 30 | this.SelectedValueChanged += (sender, e) => 31 | { 32 | this.ValueChanged?.Invoke(sender, EventArgs.Empty); 33 | this.LongValueChanged?.Invoke(sender, EventArgs.Empty); 34 | }; 35 | } 36 | 37 | [BrowsableAttribute(false)] 38 | public event EventHandler ValueChanged; 39 | 40 | [BrowsableAttribute(false)] 41 | public event EventHandler LongValueChanged; 42 | 43 | [DefaultValue(0)] 44 | [Bindable(true), Browsable(true)] 45 | public int Value 46 | { 47 | get 48 | { 49 | int itemsCount = this.Items.Count; 50 | if (itemsCount > 32) itemsCount = 32; 51 | int result = 0; 52 | for (int i = 0; i < itemsCount; i++) 53 | if (this.GetItemChecked(i)) result |= 1 << i; 54 | return result; 55 | } 56 | set 57 | { 58 | int itemsCount = this.Items.Count; 59 | if (itemsCount > 32) itemsCount = 32; 60 | this.BeginUpdate(); 61 | for (int i = 0; i < itemsCount; i++) 62 | { 63 | int j = 1 << i; 64 | bool nch = (value & j) == j; 65 | bool och = this.GetItemChecked(i); 66 | if (nch != och) this.SetItemChecked(i, nch); 67 | } 68 | this.EndUpdate(); 69 | this.LongValueChanged?.Invoke(this, EventArgs.Empty); 70 | } 71 | } 72 | 73 | [DefaultValue(0)] 74 | [Bindable(true), Browsable(true)] 75 | public long LongValue 76 | { 77 | get 78 | { 79 | int itemsCount = this.Items.Count; 80 | if (itemsCount > 64) itemsCount = 64; 81 | long result = 0; 82 | for (int i = 0; i < itemsCount; i++) 83 | if (this.GetItemChecked(i)) result |= 1L << i; 84 | return result; 85 | } 86 | set 87 | { 88 | int itemsCount = this.Items.Count; 89 | if (itemsCount > 64) itemsCount = 64; 90 | this.BeginUpdate(); 91 | for (int i = 0; i < itemsCount; i++) 92 | { 93 | long j = 1L << i; 94 | bool nch = (value & j) == j; 95 | bool och = this.GetItemChecked(i); 96 | if (nch != och) this.SetItemChecked(i, nch); 97 | } 98 | this.EndUpdate(); 99 | this.ValueChanged?.Invoke(this, EventArgs.Empty); 100 | } 101 | } 102 | 103 | public bool[] GetValues() 104 | { 105 | int itemsCount = this.Items.Count; 106 | bool[] result = new bool[itemsCount]; 107 | for (int i = 0; i < itemsCount; i++) 108 | result[i] = this.GetItemChecked(i); 109 | return result; 110 | } 111 | 112 | public void SetValues(bool[] Values) 113 | { 114 | int itemsCount = this.Items.Count; 115 | if (itemsCount > Values.Length) itemsCount = Values.Length; 116 | this.BeginUpdate(); 117 | for (int i = 0; i < itemsCount; i++) 118 | { 119 | bool nch = Values[i]; 120 | bool och = this.GetItemChecked(i); 121 | if (nch != och) this.SetItemChecked(i, nch); 122 | } 123 | this.EndUpdate(); 124 | this.ValueChanged?.Invoke(this, EventArgs.Empty); 125 | this.LongValueChanged?.Invoke(this, EventArgs.Empty); 126 | } 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Source/DataViewExtenders.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {FFE9BBB5-8B9B-40EA-9499-AA2DE0ECB1F6} 8 | Library 9 | Properties 10 | CBComponents 11 | CBComponents.DataViewExtenders 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Component 54 | 55 | 56 | 57 | Component 58 | 59 | 60 | Component 61 | 62 | 63 | 64 | Form 65 | 66 | 67 | 68 | 69 | True 70 | True 71 | Resources.resx 72 | 73 | 74 | 75 | 76 | ResXFileCodeGenerator 77 | Resources.Designer.cs 78 | 79 | 80 | 81 | 88 | -------------------------------------------------------------------------------- /Source/Forms/SortableBindingList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Reflection; 6 | 7 | namespace CBComponents.Forms 8 | { 9 | internal sealed class PropertyComparer : IComparer 10 | { 11 | private readonly IComparer comparer; 12 | private PropertyDescriptor propertyDescriptor; 13 | private int reverse; 14 | 15 | public PropertyComparer(PropertyDescriptor property, ListSortDirection direction) 16 | { 17 | this.propertyDescriptor = property; 18 | Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType); 19 | this.comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null); 20 | this.SetListSortDirection(direction); 21 | } 22 | 23 | public int Compare(T x, T y) 24 | { 25 | return this.reverse * this.comparer.Compare(this.propertyDescriptor.GetValue(x), this.propertyDescriptor.GetValue(y)); 26 | } 27 | 28 | private void SetPropertyDescriptor(PropertyDescriptor descriptor) 29 | { 30 | this.propertyDescriptor = descriptor; 31 | } 32 | 33 | private void SetListSortDirection(ListSortDirection direction) 34 | { 35 | this.reverse = direction == ListSortDirection.Ascending ? 1 : -1; 36 | } 37 | 38 | public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction) 39 | { 40 | this.SetPropertyDescriptor(descriptor); 41 | this.SetListSortDirection(direction); 42 | } 43 | } 44 | 45 | internal sealed class SortableBindingList : BindingList 46 | { 47 | private readonly Dictionary> comparers; 48 | private bool isSorted; 49 | private ListSortDirection listSortDirection; 50 | private PropertyDescriptor propertyDescriptor; 51 | 52 | public SortableBindingList() 53 | : base(new List()) 54 | { 55 | this.comparers = new Dictionary>(); 56 | } 57 | 58 | public SortableBindingList(IEnumerable enumeration) 59 | : base(new List(enumeration)) 60 | { 61 | this.comparers = new Dictionary>(); 62 | } 63 | 64 | protected override bool SupportsSortingCore 65 | { 66 | get { return true; } 67 | } 68 | 69 | protected override bool IsSortedCore 70 | { 71 | get { return this.isSorted; } 72 | } 73 | 74 | protected override PropertyDescriptor SortPropertyCore 75 | { 76 | get { return this.propertyDescriptor; } 77 | } 78 | 79 | protected override ListSortDirection SortDirectionCore 80 | { 81 | get { return this.listSortDirection; } 82 | } 83 | 84 | protected override bool SupportsSearchingCore 85 | { 86 | get { return true; } 87 | } 88 | 89 | protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction) 90 | { 91 | List itemsList = (List)this.Items; 92 | 93 | Type propertyType = property.PropertyType; 94 | PropertyComparer comparer; 95 | if (!this.comparers.TryGetValue(propertyType, out comparer)) 96 | { 97 | comparer = new PropertyComparer(property, direction); 98 | this.comparers.Add(propertyType, comparer); 99 | } 100 | 101 | comparer.SetPropertyAndDirection(property, direction); 102 | itemsList.Sort(comparer); 103 | 104 | this.propertyDescriptor = property; 105 | this.listSortDirection = direction; 106 | this.isSorted = true; 107 | 108 | this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); 109 | } 110 | 111 | protected override void RemoveSortCore() 112 | { 113 | this.isSorted = false; 114 | this.propertyDescriptor = base.SortPropertyCore; 115 | this.listSortDirection = base.SortDirectionCore; 116 | 117 | this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); 118 | } 119 | 120 | protected override int FindCore(PropertyDescriptor property, object key) 121 | { 122 | int count = this.Count; 123 | for (int i = 0; i < count; ++i) 124 | { 125 | T element = this[i]; 126 | if (property.GetValue(element).Equals(key)) 127 | { 128 | return i; 129 | } 130 | } 131 | 132 | return -1; 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /Examples/Database/daoDataSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Data; 4 | 5 | namespace Examples.Database 6 | { 7 | partial class daoDataSet 8 | { 9 | private const string fileName = "data.xml"; 10 | 11 | public static DataTable CreateSalaryGroupsLookupTable() 12 | { 13 | DataTable result = new DataTable(); 14 | result.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(byte)), new DataColumn("Group", typeof(string)) }); 15 | result.Columns[0].Unique = true; 16 | result.Rows.Add(0, "Default"); 17 | result.Rows.Add(1, "Regular"); 18 | result.Rows.Add(2, "RG+Bonus"); 19 | result.Rows.Add(3, "RET"); 20 | result.Rows.Add(4, "BIN"); 21 | return result; 22 | } 23 | 24 | public void LoadFromDatabase() 25 | { 26 | #if DEBUG 27 | daoDataSet.PrepareDatabase(); 28 | #else 29 | if (!File.Exists(fileName)) daoDataSet.PrepareDatabase(); 30 | #endif 31 | this.BeginInit(); 32 | if (this.Employees.Count > 0) this.Employees.Clear(); 33 | if (this.Departments.Count > 0) this.Departments.Clear(); 34 | this.ReadXml(fileName); 35 | this.AcceptChanges(); 36 | this.EndInit(); 37 | // Creation rows supporting 38 | this.Departments.TableNewRow += delegate (object sender, System.Data.DataTableNewRowEventArgs e) { e.Row[e.Row.Table.PrimaryKey[0]] = Guid.NewGuid(); }; 39 | this.Employees.TableNewRow += delegate (object sender, System.Data.DataTableNewRowEventArgs e) { e.Row[e.Row.Table.PrimaryKey[0]] = Guid.NewGuid(); e.Row[e.Row.Table.ParentRelations[0].ChildColumns[0]] = e.Row.Table.ParentRelations[0].ParentTable.Rows[0][e.Row.Table.ParentRelations[0].ParentColumns[0]]; }; 40 | } 41 | 42 | public void SaveToDatabase() 43 | { 44 | this.WriteXml(fileName); 45 | this.AcceptChanges(); 46 | } 47 | 48 | public static void PrepareDatabase() 49 | { 50 | daoDataSet ds = new daoDataSet(); 51 | // Departments 52 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Services", false, "MM", null); 53 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Marketing", false, "MM", null); 54 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Human Resources", false, "HR", null); 55 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Financial", false, "AM", null); 56 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Purchasing", false, "SM", null); 57 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Sales", false, "MM", null); 58 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "IT", false, "KT", null); 59 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Inventory", false, null, null); 60 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Paper printing", true, null, null); 61 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Quality Asurance", false, "KT", null); 62 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Insurance", false, "AM", null); 63 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Licenses", true, "AM", null); 64 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Operational", false, "AM", null); 65 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Staff", false, "HR", null); 66 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Customer Service", false, "MM", null); 67 | ds.Departments.AddDepartmentsRow(Guid.NewGuid(), "Organizational", false, "MN", null); 68 | // Employees 69 | var row = ds.Employees.NewEmployeesRow(); // Peter Walt 70 | row.EmployeeID = Guid.NewGuid(); 71 | row.EmployeeName = "Peter Walt"; 72 | row.DepartmentsRow = ds.Departments[1]; 73 | row.SalaryGroup = 0; 74 | row.Salary = 1230.4m; 75 | ds.Employees.AddEmployeesRow(row); 76 | row = ds.Employees.NewEmployeesRow(); // Olesea Rozhkova 77 | row.EmployeeID = Guid.NewGuid(); 78 | row.EmployeeName = "Olesea Rozhkova"; 79 | row.DepartmentsRow = ds.Departments[2]; 80 | row.PhoneNumber = 18005401234; 81 | row.DateBirth = new DateTime(1977, 03, 21); 82 | row.SalaryGroup = 1; 83 | ds.Employees.AddEmployeesRow(row); 84 | row = ds.Employees.NewEmployeesRow(); // Sima Ludlow 85 | row.EmployeeID = Guid.NewGuid(); 86 | row.EmployeeName = "Sima Ludlow"; 87 | row.DepartmentsRow = ds.Departments[3]; 88 | row.PhoneNumber = 16473455034; 89 | row.DateBirth = new DateTime(1973, 12, 1); 90 | row.SalaryGroup = 2; 91 | row.Salary = 1530.54m; 92 | ds.Employees.AddEmployeesRow(row); 93 | row = ds.Employees.NewEmployeesRow(); // Kaur Rajvinder 94 | row.EmployeeID = Guid.NewGuid(); 95 | row.EmployeeName = "Kaur Rajvinder"; 96 | row.DepartmentsRow = ds.Departments[4]; 97 | //row.PhoneNumber = 37322343456; 98 | row.DateBirth = new DateTime(1963, 11, 9); 99 | row.SalaryGroup = 2; 100 | ds.Employees.AddEmployeesRow(row); 101 | // Save created rows 102 | ds.SaveToDatabase(); 103 | } 104 | 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Examples/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Examples.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Examples.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap cell_clear { 67 | get { 68 | object obj = ResourceManager.GetObject("cell_clear", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap database_refresh { 77 | get { 78 | object obj = ResourceManager.GetObject("database_refresh", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Bitmap. 85 | /// 86 | internal static System.Drawing.Bitmap database_save { 87 | get { 88 | object obj = ResourceManager.GetObject("database_save", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Bitmap. 95 | /// 96 | internal static System.Drawing.Bitmap door { 97 | get { 98 | object obj = ResourceManager.GetObject("door", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// Looks up a localized resource of type System.Drawing.Bitmap. 105 | /// 106 | internal static System.Drawing.Bitmap more_imports { 107 | get { 108 | object obj = ResourceManager.GetObject("more_imports", resourceCulture); 109 | return ((System.Drawing.Bitmap)(obj)); 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Source/DataDescriptors/FieldDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace CBComponents.DataDescriptors 5 | { 6 | /// 7 | /// Editor mode of fields on the Panel 8 | /// 9 | public enum FieldEditorMode 10 | { 11 | Auto, 12 | TextBox, MultilineTextBox, 13 | NumberTextBox, 14 | DateTimeTextBox, 15 | BitMask, BitMask64, 16 | CheckBox, ComboBox, ComboTextBox, ListBox, 17 | GuidEditor 18 | } 19 | 20 | /// 21 | /// DataDescriptor of fields on the Panel 22 | /// 23 | public class FieldDataDescriptor 24 | { 25 | public string CaptionText { get; set; } 26 | public string ColumnName { get; set; } 27 | public FieldEditorMode Mode { get; set; } 28 | public EditorDataStyle? Style { get; set; } 29 | public bool IsNull { get; set; } 30 | public object NullValue { get; set; } 31 | public bool IsReadOnly { get; set; } 32 | public int? MaxLength { get; set; } 33 | public decimal? Minimum { get; set; } 34 | public decimal? Maximum { get; set; } 35 | public int? SizeWidth { get; set; } 36 | public object DataSource { get; set; } 37 | public string ValueMember { get; set; } 38 | public string DisplayMember { get; set; } 39 | public GetListBoxItemsDelegate GetListBoxItemsMethod { get; set; } 40 | public FormatValueDelegate FormatValueMethod { get; set; } 41 | public FieldDataDescriptor(string CaptionText, DataColumn Column, FieldEditorMode Mode = FieldEditorMode.Auto, 42 | EditorDataStyle? Style = null, int? SizeWidth = null, object NullValue = null, bool IsReadOnly = false, 43 | decimal? Minimum = null, decimal? Maximum = null, 44 | object DataSource = null, string ValueMember = null, string DisplayMember = null, 45 | GetListBoxItemsDelegate GetListBoxItemsMethod = null, FormatValueDelegate FormatValueMethod = null) 46 | { 47 | if (Mode == FieldEditorMode.Auto) 48 | { 49 | if (DataSource != null && ValueMember != null && DisplayMember != null && GetListBoxItemsMethod != null) Mode = FieldEditorMode.ListBox; 50 | else if (DataSource != null && ValueMember != null && DisplayMember != null) Mode = FieldEditorMode.ComboBox; 51 | else if (DataSource != null) Mode = FieldEditorMode.ComboTextBox; 52 | else if (FormatValueMethod != null) { Mode = FieldEditorMode.TextBox; this.IsReadOnly = true; } 53 | else if (Column.DataType == typeof(bool)) Mode = FieldEditorMode.CheckBox; 54 | else if (Column.DataType == typeof(byte)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = byte.MinValue; this.Maximum = byte.MaxValue; } 55 | else if (Column.DataType == typeof(short)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = short.MinValue; this.Maximum = short.MaxValue; } 56 | else if (Column.DataType == typeof(int)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = int.MinValue; this.Maximum = int.MaxValue; } 57 | else if (Column.DataType == typeof(long)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = long.MinValue; this.Maximum = long.MaxValue; } 58 | else if (Column.DataType == typeof(ushort)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = ushort.MinValue; this.Maximum = ushort.MaxValue; } 59 | else if (Column.DataType == typeof(uint)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = uint.MinValue; this.Maximum = uint.MaxValue; } 60 | else if (Column.DataType == typeof(ulong)) { Mode = FieldEditorMode.NumberTextBox; this.Minimum = ulong.MinValue; this.Maximum = ulong.MaxValue; } 61 | else if (Column.DataType == typeof(DateTime)) Mode = FieldEditorMode.DateTimeTextBox; 62 | else if (Column.DataType == typeof(Guid)) { Mode = FieldEditorMode.TextBox; this.IsReadOnly = true; } 63 | else if (Column.MaxLength > 260) Mode = FieldEditorMode.MultilineTextBox; 64 | else Mode = FieldEditorMode.TextBox; 65 | } 66 | if (Mode == FieldEditorMode.BitMask && (Column.DataType == typeof(long) || Column.DataType == typeof(ulong))) 67 | { 68 | Mode = FieldEditorMode.BitMask64; 69 | } 70 | this.CaptionText = CaptionText; // Column.Caption; 71 | this.ColumnName = Column.ColumnName; 72 | this.Mode = Mode; 73 | this.Style = Style; 74 | this.IsNull = Column.AllowDBNull || Mode == FieldEditorMode.GuidEditor; 75 | this.NullValue = NullValue; 76 | this.IsReadOnly = this.IsReadOnly || Column.ReadOnly || IsReadOnly || Mode == FieldEditorMode.GuidEditor; 77 | if (this.IsReadOnly && this.Mode == FieldEditorMode.NumberTextBox) this.Mode = FieldEditorMode.TextBox; 78 | if (Column.MaxLength > 0) this.MaxLength = Column.MaxLength; 79 | if (Minimum.HasValue) this.Minimum = Minimum; 80 | if (Maximum.HasValue) this.Maximum = Maximum; 81 | this.SizeWidth = SizeWidth; 82 | this.DataSource = DataSource; 83 | this.ValueMember = ValueMember; 84 | this.DisplayMember = DisplayMember; 85 | this.GetListBoxItemsMethod = GetListBoxItemsMethod; 86 | this.FormatValueMethod = FormatValueMethod; 87 | } 88 | /// 89 | /// Resulted Control after generation 90 | /// 91 | public System.Windows.Forms.Control GeneratedControl = null; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Source/Extenders/DataGridView/ColumnStyles.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // DataViewExtenders 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | using CBComponents.DataDescriptors; 20 | using CBComponents.Forms; 21 | 22 | public static partial class DataGridViewExtenders 23 | { 24 | /// 25 | /// 26 | /// 27 | /// DataGridViewColumn 28 | /// 29 | /// 30 | /// 31 | /// DataGridViewColumn 32 | public static DataGridViewColumn SetStyles(this DataGridViewColumn column, int Width, DataGridViewContentAlignment Alignment = DataGridViewContentAlignment.MiddleLeft, string Format = null) 33 | { 34 | column.Width = Width; 35 | column.DefaultCellStyle.Alignment = Alignment; 36 | if (!string.IsNullOrEmpty(Format)) column.DefaultCellStyle.Format = Format; 37 | return column; 38 | } 39 | 40 | /// 41 | /// 42 | /// 43 | /// DataGridViewColumn 44 | /// 45 | /// 46 | /// DataGridViewColumn 47 | public static DataGridViewColumn SetAutoSizeFillStyle(this DataGridViewColumn column, int MinimumWidth, float FillWeight = 100) 48 | { 49 | column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 50 | column.MinimumWidth = MinimumWidth; 51 | column.FillWeight = FillWeight; 52 | return column; 53 | } 54 | 55 | /// 56 | /// 57 | /// 58 | /// DataGridViewColumn 59 | /// DataGridViewColumn 60 | public static DataGridViewColumn SetAutoSizeAllCellsStyle(this DataGridViewColumn column) 61 | { 62 | column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; 63 | return column; 64 | } 65 | 66 | /// 67 | /// 68 | /// 69 | /// DataGridViewColumn 70 | /// 71 | /// DataGridViewColumn 72 | public static DataGridViewColumn SetNumberStyle(this DataGridViewColumn column, int Width = 80) 73 | { 74 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleRight, "N0"); 75 | } 76 | 77 | /// 78 | /// 79 | /// 80 | /// DataGridViewColumn 81 | /// 82 | /// DataGridViewColumn 83 | public static DataGridViewColumn SetDecimalStyle(this DataGridViewColumn column, int Width = 80) 84 | { 85 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleRight, "N"); 86 | } 87 | 88 | /// 89 | /// 90 | /// 91 | /// DataGridViewColumn 92 | /// 93 | /// DataGridViewColumn 94 | public static DataGridViewColumn SetMoneyStyle(this DataGridViewColumn column, int Width = 80) 95 | { 96 | // TODO: should be configured according local culture 97 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleRight, "C"); 98 | } 99 | 100 | /// 101 | /// 102 | /// 103 | /// DataGridViewColumn 104 | /// 105 | /// DataGridViewColumn 106 | public static DataGridViewColumn SetPercentStyle(this DataGridViewColumn column, int Width = 80) 107 | { 108 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleCenter, "P"); 109 | } 110 | 111 | /// 112 | /// 113 | /// 114 | /// DataGridViewColumn 115 | /// 116 | /// DataGridViewColumn 117 | public static DataGridViewColumn SetDateStyle(this DataGridViewColumn column, int Width = 110) 118 | { 119 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleCenter, "d"); 120 | } 121 | 122 | /// 123 | /// 124 | /// 125 | /// DataGridViewColumn 126 | /// 127 | /// DataGridViewColumn 128 | public static DataGridViewColumn SetDateTimeStyle(this DataGridViewColumn column, int Width = 160) 129 | { 130 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleRight, "g"); 131 | } 132 | 133 | /// 134 | /// 135 | /// 136 | /// DataGridViewColumn 137 | /// 138 | /// DataGridViewColumn 139 | public static DataGridViewColumn SetDateTimeWithSecondsStyle(this DataGridViewColumn column, int Width = 160) 140 | { 141 | return column.SetStyles(Width, DataGridViewContentAlignment.MiddleRight, "G"); 142 | } 143 | 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Examples/Examples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5981795B-49A3-4816-B886-B0A18626FE57} 8 | WinExe 9 | Properties 10 | Examples 11 | Examples 12 | v4.0 13 | 512 14 | publish\ 15 | true 16 | Disk 17 | false 18 | Foreground 19 | 7 20 | Days 21 | false 22 | false 23 | true 24 | 0 25 | 1.0.0.%2a 26 | false 27 | false 28 | true 29 | 30 | 31 | 32 | AnyCPU 33 | true 34 | full 35 | false 36 | bin\Debug\ 37 | DEBUG;TRACE 38 | prompt 39 | 4 40 | 41 | 42 | AnyCPU 43 | pdbonly 44 | true 45 | bin\Release\ 46 | TRACE 47 | prompt 48 | 4 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | daoDataSet.xsd 64 | 65 | 66 | True 67 | True 68 | daoDataSet.xsd 69 | 70 | 71 | Form 72 | 73 | 74 | Example1Form.cs 75 | 76 | 77 | Form 78 | 79 | 80 | MainForm.cs 81 | 82 | 83 | 84 | 85 | Example1Form.cs 86 | 87 | 88 | MainForm.cs 89 | 90 | 91 | ResXFileCodeGenerator 92 | Resources.Designer.cs 93 | Designer 94 | 95 | 96 | True 97 | Resources.resx 98 | True 99 | 100 | 101 | 102 | daoDataSet.xsd 103 | 104 | 105 | Designer 106 | MSDataSetGenerator 107 | daoDataSet.Designer.cs 108 | 109 | 110 | daoDataSet.xsd 111 | 112 | 113 | SettingsSingleFileGenerator 114 | Settings.Designer.cs 115 | 116 | 117 | True 118 | Settings.settings 119 | True 120 | 121 | 122 | 123 | 124 | {ffe9bbb5-8b9b-40ea-9499-aa2de0ecb1f6} 125 | DataViewExtenders 126 | 127 | 128 | 129 | 130 | False 131 | .NET Framework 3.5 SP1 132 | true 133 | 134 | 135 | 136 | 143 | -------------------------------------------------------------------------------- /Source/Forms/PromptedTextBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | namespace CBComponents.Forms 7 | { 8 | /// 9 | /// Draws a textbox with a prompt inside of it, similar to the "Quick Search" box 10 | /// in Outlook 2007, IE7 or the Firefox 2.0 search box. The prompt will disappear when 11 | /// the focus is placed in the textbox, and will not display again if the Text property 12 | /// contains any value. If the Text property is empty, then the prompt will display 13 | /// again when the textbox loses the focus. 14 | /// 15 | internal class PromptedTextBox : System.Windows.Forms.TextBox 16 | { 17 | // Windows message constants 18 | const int WM_SETFOCUS = 7; 19 | const int WM_KILLFOCUS = 8; 20 | const int WM_ERASEBKGND = 14; 21 | const int WM_PAINT = 15; 22 | 23 | // private internal variables 24 | private bool _focusSelect = true; 25 | private bool _drawPrompt = true; 26 | private string _promptText = String.Empty; 27 | private Color _promptColor = SystemColors.GrayText; 28 | private Font _promptFont = null; 29 | 30 | /// 31 | /// Public constructor 32 | /// 33 | /// Uncomment the SetStyle line to activate the OnPaint logic in place of the WndProc logic 34 | public PromptedTextBox() 35 | { 36 | //this.SetStyle(ControlStyles.UserPaint, true); 37 | this.PromptFont = this.Font; 38 | } 39 | 40 | [Browsable(true)] 41 | [EditorBrowsable(EditorBrowsableState.Always)] 42 | [Category("Appearance")] 43 | [Description("The prompt text to display when there is nothing in the Text property.")] 44 | public string PromptText 45 | { 46 | get { return _promptText; } 47 | set { _promptText = value.Trim(); this.Invalidate(); } 48 | } 49 | 50 | [Browsable(true)] 51 | [EditorBrowsable(EditorBrowsableState.Always)] 52 | [Category("Appearance")] 53 | [Description("The ForeColor to use when displaying the PromptText.")] 54 | public Color PromptForeColor 55 | { 56 | get { return _promptColor; } 57 | set { _promptColor = value; this.Invalidate(); } 58 | } 59 | 60 | [Browsable(true)] 61 | [EditorBrowsable(EditorBrowsableState.Always)] 62 | [Category("Appearance")] 63 | [Description("The Font to use when displaying the PromptText.")] 64 | public Font PromptFont 65 | { 66 | get { return _promptFont; } 67 | set { _promptFont = value; this.Invalidate(); } 68 | } 69 | 70 | [Browsable(true)] 71 | [EditorBrowsable(EditorBrowsableState.Always)] 72 | [Category("Behavior")] 73 | [Description("Automatically select the text when control receives the focus.")] 74 | public bool FocusSelect 75 | { 76 | get { return _focusSelect; } 77 | set { _focusSelect = value; } 78 | } 79 | 80 | /// 81 | /// When the textbox receives an OnEnter event, select all the text if any text is present 82 | /// 83 | /// 84 | protected override void OnEnter(EventArgs e) 85 | { 86 | if (this.Text.Length > 0 && _focusSelect) 87 | this.SelectAll(); 88 | 89 | base.OnEnter(e); 90 | } 91 | 92 | /// 93 | /// Redraw the control when the text alignment changes 94 | /// 95 | /// 96 | protected override void OnTextAlignChanged(EventArgs e) 97 | { 98 | base.OnTextAlignChanged(e); 99 | this.Invalidate(); 100 | } 101 | 102 | /// 103 | /// Redraw the control with the prompt 104 | /// 105 | /// 106 | /// This event will only fire if ControlStyles.UserPaint is set to true in the constructor 107 | protected override void OnPaint(PaintEventArgs e) 108 | { 109 | base.OnPaint(e); 110 | 111 | // Only draw the prompt in the OnPaint event and when the Text property is empty 112 | if (_drawPrompt && this.Text.Length == 0) 113 | DrawTextPrompt(e.Graphics); 114 | } 115 | 116 | /// 117 | /// Overrides the default WndProc for the control 118 | /// 119 | /// The Windows message structure 120 | /// 121 | /// This technique is necessary because the OnPaint event seems to be doing some 122 | /// extra processing that I haven't been able to figure out. 123 | /// 124 | protected override void WndProc(ref System.Windows.Forms.Message m) 125 | { 126 | switch (m.Msg) 127 | { 128 | case WM_SETFOCUS: 129 | _drawPrompt = false; 130 | break; 131 | 132 | case WM_KILLFOCUS: 133 | _drawPrompt = true; 134 | break; 135 | } 136 | 137 | base.WndProc(ref m); 138 | 139 | // Only draw the prompt on the WM_PAINT event and when the Text property is empty 140 | if (m.Msg == WM_PAINT && _drawPrompt && this.Text.Length == 0 && !this.GetStyle(ControlStyles.UserPaint)) 141 | DrawTextPrompt(); 142 | } 143 | 144 | /// 145 | /// Overload to automatically create the Graphics region before drawing the text prompt 146 | /// 147 | /// The Graphics region is disposed after drawing the prompt. 148 | protected virtual void DrawTextPrompt() 149 | { 150 | using (Graphics g = this.CreateGraphics()) 151 | { 152 | DrawTextPrompt(g); 153 | } 154 | } 155 | 156 | /// 157 | /// Draws the PromptText in the TextBox.ClientRectangle using the PromptFont and PromptForeColor 158 | /// 159 | /// The Graphics region to draw the prompt on 160 | protected virtual void DrawTextPrompt(Graphics g) 161 | { 162 | TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.Top | TextFormatFlags.EndEllipsis; 163 | Rectangle rect = this.ClientRectangle; 164 | 165 | // Offset the rectangle based on the HorizontalAlignment, 166 | // otherwise the display looks a little strange 167 | switch (this.TextAlign) 168 | { 169 | case HorizontalAlignment.Center: 170 | flags = flags | TextFormatFlags.HorizontalCenter; 171 | rect.Offset(0, 1); 172 | break; 173 | case HorizontalAlignment.Left: 174 | flags = flags | TextFormatFlags.Left; 175 | rect.Offset(1, 1); 176 | break; 177 | case HorizontalAlignment.Right: 178 | flags = flags | TextFormatFlags.Right; 179 | rect.Offset(0, 1); 180 | break; 181 | } 182 | 183 | // Draw the prompt text using TextRenderer 184 | TextRenderer.DrawText(g, _promptText, _promptFont, rect, _promptColor, this.BackColor, flags); 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /Source/Extenders/DataGridView/Preparations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // DataViewExtenders 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | using CBComponents.DataDescriptors; 20 | using CBComponents.Forms; 21 | 22 | public static partial class DataGridViewExtenders 23 | { 24 | /// 25 | /// Preparing DataGridView for showing data 26 | /// 27 | /// DataGridView 28 | /// 29 | public static void PrepareStyleForShowingData(this DataGridView dataGrid, bool IsReadOnly = true) 30 | { 31 | dataGrid.AllowUserToAddRows = false; 32 | dataGrid.AllowUserToDeleteRows = false; 33 | dataGrid.AllowUserToResizeRows = false; 34 | dataGrid.ReadOnly = IsReadOnly; 35 | dataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable; 36 | dataGrid.CellBorderStyle = DataGridViewCellBorderStyle.SingleVertical; 37 | dataGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; 38 | dataGrid.EnableHeadersVisualStyles = true; 39 | dataGrid.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; 40 | dataGrid.ColumnHeadersVisible = true; 41 | dataGrid.RowHeadersVisible = false; 42 | dataGrid.RowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = SystemColors.Control, ForeColor = SystemColors.ControlText, SelectionBackColor = SystemColors.Highlight, SelectionForeColor = SystemColors.HighlightText }; 43 | dataGrid.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = SystemColors.ControlLightLight, ForeColor = SystemColors.ControlText, SelectionBackColor = SystemColors.Highlight, SelectionForeColor = SystemColors.HighlightText }; 44 | dataGrid.BackgroundColor = SystemColors.AppWorkspace; 45 | 46 | dataGrid.MultiSelect = false; 47 | dataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 48 | dataGrid.StandardTab = true; 49 | 50 | typeof(DataGridView).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty, null, dataGrid, new object[] { true }); 51 | dataGrid.DataError += new DataGridViewDataErrorEventHandler(dataGrid_DataError); 52 | if (dataGrid.DataSource is BindingSource) ((BindingSource)dataGrid.DataSource).DataError += new BindingManagerDataErrorEventHandler(bindingSource_DataError); 53 | } 54 | 55 | /// 56 | /// Preparing DataGridView for editing data 57 | /// 58 | /// DataGridView 59 | public static void PrepareStyleForEditingData(this DataGridView dataGrid) 60 | { 61 | dataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; 62 | dataGrid.AllowUserToResizeColumns = false; 63 | dataGrid.AllowUserToResizeRows = false; 64 | //dataGrid.AllowUserToAddRows = false; 65 | dataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable; 66 | dataGrid.BorderStyle = BorderStyle.None; 67 | dataGrid.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; 68 | dataGrid.ColumnHeadersVisible = true; 69 | //dataGrid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; 70 | //dataGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; 71 | dataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; 72 | dataGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing; 73 | dataGrid.RowHeadersVisible = true; 74 | dataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; 75 | //dataGrid.RowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = SystemColors.Control, ForeColor = SystemColors.ControlText, SelectionBackColor = SystemColors.Highlight, SelectionForeColor = SystemColors.HighlightText }; 76 | //dataGrid.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = SystemColors.ControlLightLight, ForeColor = SystemColors.ControlText, SelectionBackColor = SystemColors.Highlight, SelectionForeColor = SystemColors.HighlightText }; 77 | dataGrid.BackgroundColor = SystemColors.AppWorkspace; 78 | 79 | dataGrid.MultiSelect = false; 80 | dataGrid.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; 81 | dataGrid.StandardTab = false; 82 | 83 | typeof(DataGridView).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty, null, dataGrid, new object[] { true }); 84 | dataGrid.DataError += new DataGridViewDataErrorEventHandler(dataGrid_DataError); 85 | if (dataGrid.DataSource is BindingSource) ((BindingSource)dataGrid.DataSource).DataError += new BindingManagerDataErrorEventHandler(bindingSource_DataError); 86 | dataGrid.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dataGrid_RowHeaderMouseDoubleClick); 87 | 88 | } 89 | 90 | /// 91 | /// Preparing DataGridView for report data 92 | /// 93 | /// DataGridView 94 | /// 95 | public static void PrepareStyleForShowingReportData(this DataGridView dataGrid, BindingSource bindingSource) 96 | { 97 | dataGrid.AutoGenerateColumns = false; 98 | dataGrid.DataSource = bindingSource; 99 | DataGridViewExtenders.PrepareStyleForEditingData(dataGrid); 100 | dataGrid.ReadOnly = true; 101 | dataGrid.ColumnHeadersVisible = false; 102 | dataGrid.RowHeadersVisible = false; 103 | dataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 104 | dataGrid.StandardTab = true; 105 | } 106 | 107 | private static void bindingSource_DataError(object sender, BindingManagerDataErrorEventArgs e) 108 | { 109 | // TODO: Log message - e.Exception; 110 | } 111 | 112 | private static void dataGrid_DataError(object sender, DataGridViewDataErrorEventArgs e) 113 | { 114 | FormServices.ShowError(e.Exception); 115 | e.ThrowException = false; 116 | e.Cancel = true; 117 | } 118 | 119 | private static void dataGrid_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) 120 | { 121 | if (sender is DataGridView) 122 | { 123 | var dataGrid = (DataGridView)sender; 124 | var dataBoundItem = dataGrid.Rows[e.RowIndex].DataBoundItem; 125 | if (dataBoundItem != null) 126 | SelectItemForm.ShowData(dataBoundItem, "Row inspector"); 127 | } 128 | } 129 | 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Source/Forms/RowFilterBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Specialized; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace CBComponents.Forms 11 | { 12 | internal static class RowFilterBuilder 13 | { 14 | public static string BuildColumnFilter(string filterExpression, IList table) 15 | { 16 | if (table is DataView) return RowFilterBuilder.BuildColumnFilter(filterExpression, (DataView)table); 17 | else 18 | { 19 | var _typeOfList = table.GetType(); 20 | if (_typeOfList.IsGenericType) 21 | { 22 | var _genericArguments = _typeOfList.GetGenericArguments(); 23 | if (_genericArguments.Length > 0) 24 | return RowFilterBuilder.BuildColumnFilter(filterExpression, _genericArguments[0].GetProperties().Where(c => c.PropertyType != typeof(Guid) && c.PropertyType != typeof(Boolean)).Select(c => c.Name).ToArray()); 25 | else return string.Empty; 26 | } 27 | else return string.Empty; 28 | } 29 | } 30 | 31 | public static string BuildColumnFilter(string filterExpression, DataTable table) 32 | { 33 | return BuildColumnFilter(filterExpression, table.Columns); 34 | } 35 | 36 | public static string BuildColumnFilter(string filterExpression, DataView view) 37 | { 38 | return BuildColumnFilter(filterExpression, view.Table.Columns); 39 | } 40 | 41 | public static string BuildColumnFilter(string filterExpression, DataColumnCollection columns) 42 | { 43 | StringCollection columNames = new StringCollection(); 44 | foreach (DataColumn col in columns) 45 | if (col.DataType != typeof(Guid) && col.DataType != typeof(Boolean)) 46 | columNames.Add(col.ColumnName); 47 | return BuildColumnFilter(filterExpression, columNames); 48 | } 49 | 50 | public static string BuildColumnFilter(string filterExpression, StringCollection columns) 51 | { 52 | string[] columnNames = new string[columns.Count]; 53 | columns.CopyTo(columnNames, 0); 54 | return BuildColumnFilter(filterExpression, columnNames); 55 | } 56 | 57 | public static string BuildColumnFilter(string filterExpression, DataGridView gridView) 58 | { 59 | return BuildColumnFilter(filterExpression, gridView.Columns); 60 | } 61 | 62 | public static string BuildColumnFilter(string filterExpression, DataGridViewColumnCollection columns) 63 | { 64 | // filtering TextBoxColumns 65 | StringCollection columnNames = new StringCollection(); 66 | foreach (DataGridViewColumn column in columns) 67 | if (column is DataGridViewTextBoxColumn && column.Visible && !string.IsNullOrEmpty(column.DataPropertyName)) 68 | columnNames.Add(column.DataPropertyName); 69 | string result = BuildColumnFilter(filterExpression, columnNames); 70 | // filtering ComboBoxColumns 71 | foreach (DataGridViewColumn column in columns) 72 | { 73 | var _column = column as DataGridViewComboBoxColumn; 74 | if (_column != null && _column.Visible && !string.IsNullOrEmpty(_column.DataPropertyName) && _column.DataSource != null && (_column.DataSource is IList || _column.DataSource is IListSource) && !string.IsNullOrEmpty(_column.ValueMember) && !string.IsNullOrEmpty(_column.DisplayMember)) 75 | try 76 | { 77 | StringBuilder _result = new StringBuilder(); 78 | IList _ds = _column.DataSource as IList; 79 | if (_ds == null) _ds = ((IListSource)_column.DataSource).GetList(); 80 | foreach (DataRowView _row in _ds.Cast()) 81 | if (_row[_column.DisplayMember].ToString().IndexOf(filterExpression, StringComparison.OrdinalIgnoreCase) >= 0) 82 | { 83 | if (_result.Length > 0) _result.Append(" OR "); 84 | _result.AppendFormat("(CONVERT([{0}], 'System.String') = '{1}')", _column.DataPropertyName, _row[_column.ValueMember]); 85 | } 86 | if (_result.Length > 0) 87 | { 88 | if (string.IsNullOrEmpty(result)) result = _result.ToString(); 89 | else result += " OR (" + _result.ToString() + ")"; 90 | } 91 | } 92 | catch { } 93 | } 94 | return result; 95 | } 96 | 97 | public static string BuildColumnFilter(string filterExpression, DataGridViewColumnCollection columns, DataTable relationTable, string masterDataPropertyName, string relationDataPropertyName) 98 | { 99 | // first, filtering text table columns 100 | string result = BuildColumnFilter(filterExpression, columns); 101 | // second, filtering related table columns 102 | try 103 | { 104 | var _values = relationTable.Select(BuildColumnFilter(filterExpression, relationTable)).Select(c => c[relationDataPropertyName].ToString()).Distinct(); 105 | StringBuilder _result = new StringBuilder(); 106 | foreach (var _value in _values) 107 | { 108 | if (_result.Length > 0) _result.Append(" OR "); 109 | _result.AppendFormat("(CONVERT([{0}], 'System.String') = '{1}')", masterDataPropertyName, _value); 110 | } 111 | if (_result.Length > 0) 112 | { 113 | if (string.IsNullOrEmpty(result)) result = _result.ToString(); 114 | else result += " OR (" + _result.ToString() + ")"; 115 | } 116 | } 117 | catch { } 118 | return result; 119 | } 120 | 121 | /// 122 | /// Builds a string that can be used for DataViews as Row filter. 123 | /// You might pass 2 arguments: a string that repressents the expressiuon for the filter, seperated by blancs 124 | /// and an array of coloumn names 125 | /// 126 | /// 127 | /// An Expression that might be used for filter. for Example: "Thomas Haller" 128 | /// 129 | /// An String Array with the Name of Coloumns 130 | /// for Example "Prename, Name" 131 | /// 132 | public static string BuildColumnFilter(string filterExpression, string[] columns) 133 | { 134 | if (filterExpression == null || columns.Length == 0) return string.Empty; 135 | filterExpression = filterExpression.Replace("'", "''").Replace("*", "[*]").Replace("%", "[%]"); 136 | 137 | string[] filters = filterExpression.Split(" ".ToCharArray()); 138 | StringBuilder result = new StringBuilder(); 139 | 140 | for (int i = 0; i < filters.Length; i++) 141 | { 142 | if (i != 0) result.Append(" AND "); 143 | result.Append("("); 144 | string filter = filters[i]; 145 | for (int j = 0; j < columns.Length; j++) 146 | { 147 | string column = columns[j]; 148 | if (j != 0) result.Append(" OR "); //we need an prefix "OR" for every operator - but not for the first one 149 | result.AppendFormat("(CONVERT([{0}], 'System.String') like '%{1}%')", column, filter); 150 | } 151 | result.Append(")"); 152 | } 153 | return result.ToString(); 154 | } 155 | 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /Examples/ExamplesForms/Example1Form.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | False 122 | 123 | 124 | False 125 | 126 | 127 | False 128 | 129 | 130 | False 131 | 132 | 133 | False 134 | 135 | 136 | False 137 | 138 | -------------------------------------------------------------------------------- /Examples/MainForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | using CBComponents; 11 | using CBComponents.DataDescriptors; 12 | using Examples.Database; 13 | using CBComponents.Forms; 14 | 15 | namespace Examples 16 | { 17 | public partial class MainForm : Form 18 | { 19 | public MainForm() 20 | { 21 | CBComponents.Settings.SetMainForm(this); 22 | InitializeComponent(); 23 | InitializeGridsAndPanels(); 24 | 25 | // binding data for navigators 26 | this.departmentsNavigator.BindingSource = this.departmentsBindingSource; 27 | this.employeesNavigator.BindingSource = this.employeesBindingSource; 28 | 29 | // bottom buttons 30 | this.btnLoadData.Image = Properties.Resources.database_refresh; 31 | this.btnLoadData.Click += delegate { this.Database.LoadFromDatabase(); }; 32 | this.btnSaveData.Image = Properties.Resources.database_save; 33 | this.btnSaveData.Click += delegate { this.Database.SaveToDatabase(); }; 34 | this.btnExit.Image = Properties.Resources.door; 35 | this.btnExit.Click += delegate { this.Close(); }; 36 | 37 | // Examples menu 38 | this.exMM.DropDownItems.Add(new ToolStripMenuItem(Example1Form.TextName, null, (sender, e) => { var form = new Example1Form(); form.Show(this); })); 39 | this.exMM.DropDownItems.Add("-"); 40 | this.exMM.DropDownItems.Add(new ToolStripMenuItem("SelectItemForm (IEnumerable example)", null, (sender, e) => 41 | { 42 | var items = new Dictionary(); 43 | items.Add(1, "First value"); 44 | items.Add(2, "Second value"); 45 | items.Add(3, "More values..."); 46 | using (var form = SelectItemForm.CreateFormWithoutColumns(items, "My values", "These values are mine")) 47 | { 48 | form.dataGrid.AddTextColumn("key", "Key").SetNumberStyle(); 49 | form.dataGrid.AddTextColumn("value", "Value").SetAutoSizeFillStyle(50); 50 | form.ShowDialog(); 51 | } 52 | })); 53 | this.exMM.DropDownItems.Add(new ToolStripMenuItem("SelectItemForm (DataTable example)", null, (sender, e) => 54 | { 55 | var items = new DataTable(); 56 | items.Columns.AddRange(new DataColumn[] { 57 | new DataColumn("ID", typeof(byte)), 58 | new DataColumn("Group", typeof(string)), 59 | new DataColumn("Remarks", typeof(string))}); 60 | items.Columns[0].Unique = true; 61 | items.Columns[2].AllowDBNull = true; 62 | items.Rows.Add(0, "Default"); 63 | items.Rows.Add(1, "Regular", "Regular group"); 64 | items.Rows.Add(2, "RG+Bonus", "Regular group with bonuses"); 65 | items.Rows.Add(3, "RET"); 66 | items.Rows.Add(4, "BIN"); 67 | using (var form = SelectItemForm.CreateFormWithoutColumns(items, "Groups")) 68 | { 69 | form.dataGrid.AddTextColumn(items.Columns[0].ColumnName, "ID").SetNumberStyle(); 70 | form.dataGrid.AddTextColumn(items.Columns[1].ColumnName, "Group"); 71 | form.dataGrid.AddTextColumn(items.Columns[2].ColumnName, "Remarks").SetAutoSizeFillStyle(50); 72 | form.ShowDialog(); 73 | } 74 | })); 75 | //this.exMM.DropDownItems.Add("-"); 76 | //this.exMM.DropDownItems.Add(new ToolStripMenuItem(Example2Form.TextName, null, (sender, e) => { var form = new Example3Form(); form.Show(this); })); 77 | } 78 | 79 | private void InitializeGridsAndPanels() 80 | { 81 | this.Database.LoadFromDatabase(); 82 | 83 | // praparing Grids 84 | var tbl1 = this.Database.Departments; 85 | this.departmentsGridView.GenerateColumns(this.departmentsBindingSource, 86 | new ColumnDataDescriptor("Department", tbl1.DepartmentNameColumn), 87 | new ColumnDataDescriptor("Is closed?", tbl1.IsClosedColumn), 88 | new ColumnDataDescriptor("Group", tbl1.CompanyGroupColumn), 89 | new ColumnDataDescriptor("Remarks", tbl1.RemarksColumn, FillWeight: 100)); 90 | this.departmentsGridView.PrepareStyleForEditingData(); 91 | this.departmentsGridView.AddDataRowStateDrawingInRowHeaders(); 92 | 93 | var tbl2 = this.Database.Employees; 94 | var _salaryGroups = daoDataSet.CreateSalaryGroupsLookupTable(); 95 | this.employeesGridView.GenerateColumns(this.employeesBindingSource, 96 | new ColumnDataDescriptor("Employee", tbl2.EmployeeNameColumn, FillWeight: 100), 97 | new ColumnDataDescriptor("Department", tbl2.DepartmentIDColumn, DataSource: tbl1, ValueMember: tbl1.DepartmentIDColumn.ColumnName, DisplayMember: tbl1.DepartmentNameColumn.ColumnName), 98 | new ColumnDataDescriptor("Phone", tbl2.PhoneNumberColumn, Mode: ColumnEditorMode.TextBox, FormatValueMethod: new FormatValueDelegate(this.FormatPhoneValue)), 99 | new ColumnDataDescriptor("Date of birth", tbl2.DateBirthColumn, Style: EditorDataStyle.Date), 100 | new ColumnDataDescriptor("Group of Salary", tbl2.SalaryGroupColumn, DataSource: _salaryGroups, ValueMember: _salaryGroups.Columns[0].ColumnName, DisplayMember: _salaryGroups.Columns[1].ColumnName), 101 | new ColumnDataDescriptor("Salary", tbl2.SalaryColumn, Style: EditorDataStyle.Money)); 102 | this.employeesGridView.PrepareStyleForEditingData(); 103 | this.employeesGridView.AddDataRowStateDrawingInRowHeaders(); 104 | 105 | // preparing Panels 106 | this.departmentsPanel.GenerateGroups(this.toolTip, this.departmentsBindingSource, 107 | new GroupDataDescriptor("Identifications", 108 | new FieldDataDescriptor("ID", tbl1.DepartmentIDColumn, IsReadOnly: true), 109 | new FieldDataDescriptor("Department", tbl1.DepartmentNameColumn)), 110 | new GroupDataDescriptor("Overview", (int)DataDescriptorSizeWidth.Smaller, 111 | new FieldDataDescriptor("Is closed", tbl1.IsClosedColumn), 112 | new FieldDataDescriptor("Group", tbl1.CompanyGroupColumn, DataSource: new string[] { "AM", "HR", "MM", "MN", "KT", "SM" })), 113 | new GroupDataDescriptor("Additions", 114 | new FieldDataDescriptor("Remarks", tbl1.RemarksColumn))); 115 | 116 | this.employeesPanel.GenerateGroups(this.toolTip, this.employeesBindingSource, 117 | new GroupDataDescriptor("Identifications", 118 | new FieldDataDescriptor("ID", tbl2.EmployeeIDColumn, IsReadOnly: true), 119 | new FieldDataDescriptor("Employee", tbl2.EmployeeNameColumn), 120 | new FieldDataDescriptor("Department", tbl2.DepartmentIDColumn, DataSource: tbl1, ValueMember: tbl1.DepartmentIDColumn.ColumnName, DisplayMember: tbl1.DepartmentNameColumn.ColumnName)), 121 | new GroupDataDescriptor("Overview", (int)DataDescriptorSizeWidth.Small + (int)DataDescriptorSizeWidth.Smaller, 122 | new FieldDataDescriptor("Phone", tbl2.PhoneNumberColumn, Mode: FieldEditorMode.TextBox, FormatValueMethod: new FormatValueDelegate(this.FormatPhoneValue)), 123 | new FieldDataDescriptor("Date of birth", tbl2.DateBirthColumn, Style: EditorDataStyle.Date)), 124 | new GroupDataDescriptor("Salary", (int)DataDescriptorSizeWidth.Small, 125 | new FieldDataDescriptor("Group", tbl2.SalaryGroupColumn, Mode: FieldEditorMode.ListBox, DataSource: _salaryGroups, ValueMember: _salaryGroups.Columns[0].ColumnName, DisplayMember: _salaryGroups.Columns[1].ColumnName), 126 | new FieldDataDescriptor("Salary", tbl2.SalaryColumn, Style: EditorDataStyle.Money))); 127 | 128 | } 129 | 130 | private object FormatPhoneValue(object DataBoundItem, string DataPropertyName) 131 | { 132 | if (DataBoundItem is DataRowView) 133 | { 134 | var _row = ((DataRowView)DataBoundItem).Row; 135 | if (!_row.IsNull(DataPropertyName)) 136 | { 137 | long _phone = (long)_row[DataPropertyName]; 138 | return string.Format("{0:+# (###)-###-####}", _phone); 139 | } 140 | else return null; 141 | } 142 | return null; 143 | } 144 | 145 | private void MainForm_Load(object sender, EventArgs e) 146 | { 147 | 148 | } 149 | 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Examples/Database/daoDataSet.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Examples/ExamplesForms/Example1Form.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Examples 2 | { 3 | partial class Example1Form 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.Windows.Forms.FlowLayoutPanel mainPanel; 32 | System.Windows.Forms.TableLayoutPanel tableLayoutPanel; 33 | System.Windows.Forms.Label label1; 34 | System.Windows.Forms.Label label2; 35 | System.Windows.Forms.Label label3; 36 | System.Windows.Forms.Label label4; 37 | this.bmclBox = new CBComponents.BitMaskCheckedListBox(); 38 | this.textBoxValue = new System.Windows.Forms.TextBox(); 39 | this.textBoxLongValue = new System.Windows.Forms.TextBox(); 40 | this.textBoxValues = new System.Windows.Forms.TextBox(); 41 | mainPanel = new System.Windows.Forms.FlowLayoutPanel(); 42 | tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 43 | label1 = new System.Windows.Forms.Label(); 44 | label2 = new System.Windows.Forms.Label(); 45 | label3 = new System.Windows.Forms.Label(); 46 | label4 = new System.Windows.Forms.Label(); 47 | mainPanel.SuspendLayout(); 48 | tableLayoutPanel.SuspendLayout(); 49 | this.SuspendLayout(); 50 | // 51 | // mainPanel 52 | // 53 | mainPanel.AutoScroll = true; 54 | mainPanel.AutoSize = true; 55 | mainPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 56 | mainPanel.Controls.Add(tableLayoutPanel); 57 | mainPanel.Dock = System.Windows.Forms.DockStyle.Fill; 58 | mainPanel.Location = new System.Drawing.Point(0, 0); 59 | mainPanel.Name = "mainPanel"; 60 | mainPanel.Padding = new System.Windows.Forms.Padding(6); 61 | mainPanel.Size = new System.Drawing.Size(464, 362); 62 | mainPanel.TabIndex = 0; 63 | // 64 | // tableLayoutPanel 65 | // 66 | tableLayoutPanel.AutoSize = true; 67 | tableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 68 | tableLayoutPanel.ColumnCount = 2; 69 | tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 70 | tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 71 | tableLayoutPanel.Controls.Add(label1, 0, 0); 72 | tableLayoutPanel.Controls.Add(label2, 0, 1); 73 | tableLayoutPanel.Controls.Add(label3, 0, 2); 74 | tableLayoutPanel.Controls.Add(label4, 0, 3); 75 | tableLayoutPanel.Controls.Add(this.bmclBox, 1, 0); 76 | tableLayoutPanel.Controls.Add(this.textBoxValue, 1, 1); 77 | tableLayoutPanel.Controls.Add(this.textBoxLongValue, 1, 2); 78 | tableLayoutPanel.Controls.Add(this.textBoxValues, 1, 3); 79 | tableLayoutPanel.Location = new System.Drawing.Point(9, 9); 80 | tableLayoutPanel.Name = "tableLayoutPanel"; 81 | tableLayoutPanel.RowCount = 4; 82 | tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 83 | tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 84 | tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 85 | tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 86 | tableLayoutPanel.Size = new System.Drawing.Size(397, 318); 87 | tableLayoutPanel.TabIndex = 0; 88 | // 89 | // label1 90 | // 91 | label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 92 | label1.AutoSize = true; 93 | label1.Location = new System.Drawing.Point(42, 6); 94 | label1.Margin = new System.Windows.Forms.Padding(3, 6, 3, 0); 95 | label1.Name = "label1"; 96 | label1.Size = new System.Drawing.Size(26, 13); 97 | label1.TabIndex = 1; 98 | label1.Text = "List:"; 99 | label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 100 | // 101 | // label2 102 | // 103 | label2.Anchor = System.Windows.Forms.AnchorStyles.Right; 104 | label2.AutoSize = true; 105 | label2.Location = new System.Drawing.Point(31, 166); 106 | label2.Name = "label2"; 107 | label2.Size = new System.Drawing.Size(37, 13); 108 | label2.TabIndex = 2; 109 | label2.Text = "Value:"; 110 | label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 111 | // 112 | // label3 113 | // 114 | label3.Anchor = System.Windows.Forms.AnchorStyles.Right; 115 | label3.AutoSize = true; 116 | label3.Location = new System.Drawing.Point(7, 192); 117 | label3.Name = "label3"; 118 | label3.Size = new System.Drawing.Size(61, 13); 119 | label3.TabIndex = 3; 120 | label3.Text = "LongValue:"; 121 | label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 122 | // 123 | // label4 124 | // 125 | label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 126 | label4.AutoSize = true; 127 | label4.Location = new System.Drawing.Point(3, 218); 128 | label4.Margin = new System.Windows.Forms.Padding(3, 6, 3, 0); 129 | label4.Name = "label4"; 130 | label4.Size = new System.Drawing.Size(65, 13); 131 | label4.TabIndex = 5; 132 | label4.Text = "GetValues():"; 133 | label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 134 | // 135 | // bmclBox 136 | // 137 | this.bmclBox.CheckOnClick = true; 138 | this.bmclBox.Location = new System.Drawing.Point(74, 3); 139 | this.bmclBox.LongValue = ((long)(0)); 140 | this.bmclBox.MultiColumn = true; 141 | this.bmclBox.Name = "bmclBox"; 142 | this.bmclBox.Size = new System.Drawing.Size(320, 154); 143 | this.bmclBox.TabIndex = 0; 144 | // 145 | // textBoxValue 146 | // 147 | this.textBoxValue.Location = new System.Drawing.Point(74, 163); 148 | this.textBoxValue.Name = "textBoxValue"; 149 | this.textBoxValue.Size = new System.Drawing.Size(100, 20); 150 | this.textBoxValue.TabIndex = 1; 151 | // 152 | // textBoxLongValue 153 | // 154 | this.textBoxLongValue.Location = new System.Drawing.Point(74, 189); 155 | this.textBoxLongValue.Name = "textBoxLongValue"; 156 | this.textBoxLongValue.Size = new System.Drawing.Size(200, 20); 157 | this.textBoxLongValue.TabIndex = 4; 158 | // 159 | // textBoxValues 160 | // 161 | this.textBoxValues.Location = new System.Drawing.Point(74, 215); 162 | this.textBoxValues.Multiline = true; 163 | this.textBoxValues.Name = "textBoxValues"; 164 | this.textBoxValues.ReadOnly = true; 165 | this.textBoxValues.Size = new System.Drawing.Size(320, 100); 166 | this.textBoxValues.TabIndex = 6; 167 | // 168 | // Example1Form 169 | // 170 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 171 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 172 | this.AutoSize = true; 173 | this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 174 | this.ClientSize = new System.Drawing.Size(464, 362); 175 | this.Controls.Add(mainPanel); 176 | this.MinimumSize = new System.Drawing.Size(200, 120); 177 | this.Name = "Example1Form"; 178 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 179 | this.Text = "ExamplesForm"; 180 | this.Load += new System.EventHandler(this.ExamplesForm_Load); 181 | mainPanel.ResumeLayout(false); 182 | mainPanel.PerformLayout(); 183 | tableLayoutPanel.ResumeLayout(false); 184 | tableLayoutPanel.PerformLayout(); 185 | this.ResumeLayout(false); 186 | this.PerformLayout(); 187 | 188 | } 189 | 190 | #endregion 191 | private CBComponents.BitMaskCheckedListBox bmclBox; 192 | private System.Windows.Forms.TextBox textBoxValue; 193 | private System.Windows.Forms.TextBox textBoxLongValue; 194 | private System.Windows.Forms.TextBox textBoxValues; 195 | } 196 | } -------------------------------------------------------------------------------- /Source/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | 123 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 124 | YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AA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EFkb2JlIEltYWdlUmVhZHlxyWU8AAABxUlEQVQ4T6VT2S5DURS9Ymyb 155 | 8Cie+wl+QYgvqBi/Q1TFEA+IR1IvQlCV0EHvNUREokpiSCRSVTok6JDG8IIYYtl7t6o1PbCSlb33uXut 156 | M9xzlKq+lZtyiwadWUNph4YyoZqJ3+fcyxrWKpz8FaxVdGY1XW3WAFv1gK8OFvUc2K4Vfsl9lHupl8Ba 157 | RUfLYphdIVg8UfRoUfQvhdGrRYSf8241ArM7JBrWkoFHCv8dcHIPhB+BwaUAos8QDn3Kw09AgPoYrM0a 158 | hMgg8gDEXoDRtQBuaYw5tn6Sl19TjFMPI89gYPEIw5ofVmoqaXJB3+qGvoVIUUeRaWhLxwKTQzR6PoOy 159 | jEGClpYiZ9qBNPUthtDtPEOXg3kq5LqX9l/a7BaNoTPH4IrEt6+Sygrse0lM7sQw4fsg17N7CRTTd0ae 160 | wcjyEayrfti8QTGY242T6BLj3ossubbTeFHjNwa0A2TORhoWaKaZ7UtMbX2Q6/mfDHJRRCvQDlNwHSTh 161 | 2E9kyTWP83eGGLxfpOn1Y9g2juHyBaE0OGWfPFNhozNLrlmsmJyiEYP/vIWKLnoLle1zG+nXqMrV5Mj/ 162 | l91/I4tZqxCMxOq/UTG+AT4l5cL9A3IGAAAAAElFTkSuQmCC 163 | 164 | 165 | -------------------------------------------------------------------------------- /Source/Forms/HeaderTableLayoutPanel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Drawing; 4 | using System.Drawing.Drawing2D; 5 | using System.Windows.Forms; 6 | 7 | // 8 | // HeaderTableLayoutPanel 9 | // 10 | // Extenders for WinForms controls, such as DataGridView, 11 | // BindingSource, BindingNavigator and so on 12 | // 13 | // Author: Radu Martin (CanadianBeaver) 14 | // Email: radu.martin@hotmail.com 15 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 16 | // 17 | 18 | namespace CBComponents 19 | { 20 | [ToolboxBitmap(typeof(TableLayoutPanel))] 21 | public class HeaderTableLayoutPanel : System.Windows.Forms.TableLayoutPanel 22 | { 23 | /// 24 | /// Header text 25 | /// 26 | [Browsable(true), DefaultValue(null), Category("Header"), Description("Header text")] 27 | public string CaptionText 28 | { 29 | get { return this.captionText; } 30 | set 31 | { 32 | if (this.captionText != value) 33 | { 34 | this.captionText = value; 35 | this.CalculateCaptionParams(); 36 | Invalidate(); 37 | } 38 | } 39 | } 40 | private string captionText = null; 41 | 42 | /// 43 | /// Drawing styles for Header 44 | /// 45 | public enum HighlightCaptionStyle 46 | { 47 | ForeColor, HighlightColor, ForeStyle, HighlightStyle, NavisionAxaptaStyle, GroupBoxStyle 48 | } 49 | 50 | /// 51 | /// Drawing header style 52 | /// 53 | [Browsable(true), DefaultValue(HighlightCaptionStyle.ForeColor), Category("Header"), Description("Drawing header style")] 54 | public HighlightCaptionStyle CaptionStyle 55 | { 56 | get { return this.captionStyle; } 57 | set 58 | { 59 | if (this.captionStyle != value) 60 | { 61 | this.captionStyle = value; 62 | this.CalculateCaptionParams(); 63 | Invalidate(); 64 | } 65 | } 66 | } 67 | private HighlightCaptionStyle captionStyle = HighlightCaptionStyle.ForeColor; 68 | 69 | /// 70 | /// Width of the header line 71 | /// 72 | [Browsable(true), DefaultValue((byte)2), Category("Header"), Description("Width of the header line")] 73 | public byte CaptionLineWidth 74 | { 75 | get { return this.captionLineWidth; } 76 | set 77 | { 78 | if (this.captionLineWidth != value) 79 | { 80 | this.captionLineWidth = value; 81 | this.CalculateCaptionParams(); 82 | Invalidate(); 83 | } 84 | } 85 | } 86 | private byte captionLineWidth = 2; 87 | 88 | protected override void OnForeColorChanged(EventArgs e) 89 | { 90 | base.OnForeColorChanged(e); 91 | this.CalculateCaptionParams(); 92 | Invalidate(); 93 | } 94 | 95 | protected override void OnBackColorChanged(EventArgs e) 96 | { 97 | base.OnBackColorChanged(e); 98 | this.CalculateCaptionParams(); 99 | Invalidate(); 100 | } 101 | 102 | protected override void OnFontChanged(EventArgs e) 103 | { 104 | base.OnFontChanged(e); 105 | this.CalculateCaptionParams(); 106 | Invalidate(); 107 | } 108 | 109 | // calculating and storing params for drawing 110 | private int captionTextWidth; 111 | private int captionTextHeight; 112 | private Color captionTextColor; 113 | private Color captionLineBeginColor; 114 | private Color captionLineEndColor; 115 | private void CalculateCaptionParams() 116 | { 117 | if (!string.IsNullOrEmpty(this.captionText)) 118 | using (var g = this.CreateGraphics()) 119 | { 120 | var _size = g.MeasureString(this.captionText + "I", this.Font).ToSize(); 121 | this.captionTextWidth = _size.Width; 122 | this.captionTextHeight = _size.Height; 123 | } 124 | else 125 | { 126 | this.captionTextWidth = 0; 127 | this.captionTextHeight = 0; 128 | } 129 | if (this.captionStyle == HighlightCaptionStyle.ForeColor) 130 | { 131 | this.captionTextColor = this.ForeColor; 132 | this.captionLineBeginColor = this.ForeColor; 133 | this.captionLineEndColor = this.BackColor; 134 | } 135 | else if (this.captionStyle == HighlightCaptionStyle.ForeStyle) 136 | { 137 | this.captionTextColor = this.BackColor; 138 | this.captionLineBeginColor = this.ForeColor; 139 | this.captionLineEndColor = this.BackColor; 140 | } 141 | else 142 | { 143 | this.captionTextColor = this.captionStyle == HighlightCaptionStyle.HighlightStyle ? SystemColors.HighlightText : SystemColors.Highlight; 144 | this.captionLineBeginColor = SystemColors.MenuHighlight; 145 | this.captionLineEndColor = this.BackColor; 146 | } 147 | } 148 | 149 | // changing Rectangle according CaptionText and CaptionStyle 150 | public override Rectangle DisplayRectangle 151 | { 152 | get 153 | { 154 | var result = base.DisplayRectangle; 155 | int resize = 0; 156 | if (this.captionTextHeight > 0) 157 | { 158 | resize = this.captionTextHeight; 159 | if (this.captionStyle == HighlightCaptionStyle.NavisionAxaptaStyle) resize += 1; 160 | else if (this.captionStyle == HighlightCaptionStyle.ForeStyle || this.captionStyle == HighlightCaptionStyle.HighlightStyle) resize += 1; 161 | else if (this.captionStyle != HighlightCaptionStyle.GroupBoxStyle) resize += this.captionLineWidth > 0 ? 2 : 1; 162 | } 163 | else if (this.captionStyle == HighlightCaptionStyle.GroupBoxStyle) resize += 10; 164 | if (this.captionStyle == HighlightCaptionStyle.ForeStyle || this.captionStyle == HighlightCaptionStyle.HighlightStyle) resize += this.captionLineWidth * 2; 165 | else if (this.captionStyle == HighlightCaptionStyle.ForeColor || this.captionStyle == HighlightCaptionStyle.HighlightColor) resize += this.captionLineWidth; 166 | result.Height -= resize; 167 | result.Offset(0, resize); 168 | return result; 169 | } 170 | } 171 | 172 | // changing Size according CaptionText and CaptionStyle 173 | protected override Size SizeFromClientSize(Size clientSize) 174 | { 175 | var result = base.SizeFromClientSize(clientSize); 176 | int resize = 0; 177 | if (this.captionTextHeight > 0) 178 | { 179 | resize = this.captionTextHeight; 180 | if (this.captionStyle == HighlightCaptionStyle.NavisionAxaptaStyle) resize += 1; 181 | else if (this.captionStyle == HighlightCaptionStyle.ForeStyle || this.captionStyle == HighlightCaptionStyle.HighlightStyle) resize += 1; 182 | else if (this.captionStyle != HighlightCaptionStyle.GroupBoxStyle) resize += this.captionLineWidth > 0 ? 2 : 1; 183 | } 184 | else if (this.captionStyle == HighlightCaptionStyle.GroupBoxStyle) resize += 10; 185 | if (this.captionStyle == HighlightCaptionStyle.ForeStyle || this.captionStyle == HighlightCaptionStyle.HighlightStyle) resize += this.captionLineWidth * 2; 186 | else if (this.captionStyle == HighlightCaptionStyle.ForeColor || this.captionStyle == HighlightCaptionStyle.HighlightColor) resize += this.captionLineWidth; 187 | result.Height += resize; 188 | return result; 189 | } 190 | 191 | protected override void OnPaint(PaintEventArgs e) 192 | { 193 | base.OnPaint(e); 194 | // draw gradient 195 | if (this.captionStyle == HighlightCaptionStyle.ForeStyle || this.captionStyle == HighlightCaptionStyle.HighlightStyle) 196 | { // HighlightCaptionStyle.HighlightStyle allways draw 197 | float _wPen = this.captionLineWidth * 2 + this.captionTextHeight; 198 | if (_wPen > 0) 199 | using (Brush _gBrush = new LinearGradientBrush(new Point(0, 0), new Point(this.Width, 0), this.captionLineBeginColor, this.captionLineEndColor)) 200 | using (Pen _gPen = new Pen(_gBrush, _wPen)) 201 | e.Graphics.DrawLine(_gPen, 0, _wPen / 2, this.Width, _wPen / 2); 202 | } 203 | else if (this.captionStyle == HighlightCaptionStyle.GroupBoxStyle) 204 | { // HighlightCaptionStyle.GroupBox draw GroupBox canvas 205 | string _capText = this.captionText; 206 | if (!string.IsNullOrEmpty(_capText)) 207 | { 208 | _capText = _capText.Trim(); 209 | if (!string.IsNullOrEmpty(_capText)) _capText = string.Format(" {0} ", _capText); 210 | } 211 | GroupBoxRenderer.DrawGroupBox(e.Graphics, this.ClientRectangle, _capText, this.Font, this.captionTextColor, this.Enabled ? System.Windows.Forms.VisualStyles.GroupBoxState.Normal : System.Windows.Forms.VisualStyles.GroupBoxState.Disabled); 212 | } 213 | else if (this.captionLineWidth > 0) 214 | if (this.captionStyle != HighlightCaptionStyle.NavisionAxaptaStyle) 215 | { // HighlightCaptionMode.ForeColor | HighlightCaptionMode.HighlightColor 216 | using (Brush _gradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(this.Width, 0), this.captionLineBeginColor, this.captionLineEndColor)) 217 | using (Pen _gradientPen = new Pen(_gradientBrush, this.captionLineWidth)) 218 | e.Graphics.DrawLine(_gradientPen, 0, this.captionTextHeight + this.captionLineWidth / 2, this.Width, this.captionTextHeight + this.captionLineWidth / 2); 219 | } 220 | else if (this.captionTextWidth + 1 < this.Width) 221 | { // HighlightCaptionMode.NavisionAxapta 222 | using (Brush _gradientBrush = new LinearGradientBrush(new Point(this.captionTextWidth, 0), new Point(this.Width, 0), this.captionLineBeginColor, this.captionLineEndColor)) 223 | using (Pen _gradientPen = new Pen(_gradientBrush, this.captionLineWidth > this.captionTextHeight ? this.captionTextHeight : this.captionLineWidth)) 224 | e.Graphics.DrawLine(_gradientPen, this.captionTextWidth, this.captionTextHeight / 2 + 1, this.Width, this.captionTextHeight / 2 + 1); 225 | } 226 | // draw Text 227 | if (this.captionTextHeight > 0 && this.captionStyle != HighlightCaptionStyle.GroupBoxStyle) 228 | using (Brush _textBrush = new SolidBrush(this.captionTextColor)) 229 | e.Graphics.DrawString(this.captionText, this.Font, _textBrush, 0, this.captionStyle == HighlightCaptionStyle.HighlightStyle || this.captionStyle == HighlightCaptionStyle.ForeStyle ? this.CaptionLineWidth : 0); 230 | } 231 | 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /Source/Extenders/DataGridView/ColumnsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | 6 | // 7 | // DataViewExtenders 8 | // 9 | // Extenders for WinForms controls, such as DataGridView, 10 | // BindingSource, BindingNavigator and so on 11 | // 12 | // Author: Radu Martin (CanadianBeaver) 13 | // Email: radu.martin@hotmail.com 14 | // GitHub: https://github.com/CanadianBeaver/DataViewExtenders 15 | // 16 | 17 | namespace CBComponents 18 | { 19 | using CBComponents.DataDescriptors; 20 | using CBComponents.Forms; 21 | 22 | public static partial class DataGridViewExtenders 23 | { 24 | /// 25 | /// Columns generator that works on column data descriptions (ColumnDataDescriptor) 26 | /// 27 | /// DataGridView 28 | /// Data Source to support data-binding 29 | /// Column data descriptors 30 | public static void GenerateColumns(this DataGridView dataGrid, object DataSource, params ColumnDataDescriptor[] Columns) 31 | { 32 | dataGrid.SuspendLayout(); 33 | dataGrid.AutoGenerateColumns = false; 34 | dataGrid.Columns.Clear(); 35 | foreach (var column in Columns) 36 | { 37 | if (column.Mode == ColumnEditorMode.TextBox) 38 | { 39 | var newColumn = new DataGridViewTextBoxColumn(); 40 | column.GeneratedDataGridViewColumn = newColumn; 41 | newColumn.SortMode = DataGridViewColumnSortMode.Automatic; 42 | newColumn.HeaderText = column.HeaderText; 43 | if (column.MaxLength.HasValue) newColumn.MaxInputLength = column.MaxLength.Value; 44 | if (newColumn.MaxInputLength > 260) newColumn.DefaultCellStyle = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True }; 45 | if (column.FillWeight.HasValue) 46 | { 47 | newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 48 | newColumn.FillWeight = column.FillWeight.Value; 49 | newColumn.MinimumWidth = column.HeaderText.Length * 10; 50 | if (newColumn.MinimumWidth < 50) newColumn.MinimumWidth = 50; 51 | } 52 | newColumn.ToolTipText = column.ColumnName; 53 | newColumn.DataPropertyName = column.ColumnName; 54 | if (column.NullValue != null) { if (newColumn.DefaultCellStyle != null) newColumn.DefaultCellStyle.NullValue = column.NullValue; else newColumn.DefaultCellStyle = new DataGridViewCellStyle() { NullValue = column.NullValue }; } 55 | newColumn.ReadOnly = column.IsReadOnly; 56 | if (column.Style.HasValue) DataGridViewExtenders.SetEditorDataStyle(newColumn, column.Style.Value); 57 | dataGrid.Columns.Add(newColumn); 58 | if (column.FormatValueMethod != null) 59 | { 60 | newColumn.Tag = column.FormatValueMethod; 61 | dataGrid.CellFormatting += delegate (object sender, DataGridViewCellFormattingEventArgs e) 62 | { 63 | var _data = newColumn.Tag as FormatValueDelegate; 64 | if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) 65 | { 66 | var _value = _data.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); 67 | if (_value != null) 68 | { 69 | e.Value = _value; 70 | e.FormattingApplied = _value is string; 71 | } 72 | } 73 | }; 74 | } 75 | } 76 | else if (column.Mode == ColumnEditorMode.CheckBox) 77 | { 78 | var newColumn = new DataGridViewCheckBoxColumn(); 79 | column.GeneratedDataGridViewColumn = newColumn; 80 | newColumn.SortMode = DataGridViewColumnSortMode.Automatic; 81 | newColumn.HeaderText = column.HeaderText; 82 | if (column.FillWeight.HasValue) 83 | { 84 | newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 85 | newColumn.FillWeight = column.FillWeight.Value; 86 | newColumn.MinimumWidth = column.HeaderText.Length * 10; 87 | if (newColumn.MinimumWidth < 50) newColumn.MinimumWidth = 50; 88 | } 89 | newColumn.ToolTipText = column.ColumnName; 90 | newColumn.ThreeState = column.IsNull; 91 | newColumn.DataPropertyName = column.ColumnName; 92 | newColumn.ReadOnly = column.IsReadOnly; 93 | dataGrid.Columns.Add(newColumn); 94 | } 95 | else if (column.Mode == ColumnEditorMode.ListBox) 96 | { 97 | DataGridViewColumn newColumn; 98 | if (column.IsReadOnly) 99 | { 100 | var _newColumn = new DataGridViewTextBoxColumn(); 101 | newColumn = _newColumn; 102 | } 103 | else 104 | { 105 | var _newColumn = new DataGridViewLinkColumn(); 106 | _newColumn.TrackVisitedState = false; 107 | _newColumn.LinkBehavior = LinkBehavior.HoverUnderline; 108 | newColumn = _newColumn; 109 | } 110 | column.GeneratedDataGridViewColumn = newColumn; 111 | newColumn.SortMode = DataGridViewColumnSortMode.Automatic; 112 | newColumn.HeaderText = column.HeaderText; 113 | if (column.FillWeight.HasValue) 114 | { 115 | newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 116 | newColumn.FillWeight = column.FillWeight.Value; 117 | newColumn.MinimumWidth = column.HeaderText.Length * 10; 118 | if (newColumn.MinimumWidth < 50) newColumn.MinimumWidth = 50; 119 | } 120 | newColumn.ToolTipText = column.ColumnName; 121 | newColumn.DataPropertyName = column.ColumnName; 122 | newColumn.ReadOnly = true; 123 | if (column.Style.HasValue) DataGridViewExtenders.SetEditorDataStyle(newColumn, column.Style.Value); 124 | newColumn.Tag = Tuple.Create(column.DataSource, column.ValueMember, column.DisplayMember, column.GetListBoxItemsMethod, column.FormatValueMethod); 125 | dataGrid.Columns.Add(newColumn); 126 | dataGrid.CellFormatting += delegate (object sender, DataGridViewCellFormattingEventArgs e) 127 | { 128 | var _data = newColumn.Tag as Tuple; 129 | if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) 130 | { 131 | if (_data.Item5 != null) 132 | { 133 | var _value = _data.Item5.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); 134 | if (_value != null) 135 | { 136 | e.Value = _value; 137 | e.FormattingApplied = _value is string; 138 | } 139 | } 140 | else if (dataGrid.Rows[e.RowIndex].DataBoundItem is DataRowView && (_data.Item1 is DataView || _data.Item1 is DataTable)) 141 | { 142 | var dataBoundItem = (DataRowView)dataGrid.Rows[e.RowIndex].DataBoundItem; 143 | var _data1 = _data.Item1 is DataView ? ((DataView)_data.Item1).Table : (DataTable)_data.Item1; 144 | var _row = _data1.Rows.Find(dataBoundItem[newColumn.DataPropertyName]); 145 | e.Value = _row != null ? _row[_data.Item3].ToString() : string.Empty; 146 | e.FormattingApplied = true; 147 | } 148 | } 149 | }; 150 | if (!column.IsReadOnly) 151 | dataGrid.CellClick += delegate (object sender, DataGridViewCellEventArgs e) 152 | { 153 | var _data = newColumn.Tag as Tuple; 154 | if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0 && dataGrid.Rows[e.RowIndex].DataBoundItem is DataRowView) 155 | { 156 | var dataBoundItem = (DataRowView)dataGrid.Rows[e.RowIndex].DataBoundItem; 157 | object items = _data.Item1; 158 | bool agc = false; 159 | if (_data.Item4 != null) 160 | { 161 | items = _data.Item4.Invoke(); 162 | if (items == null) 163 | { 164 | FormServices.ShowError("No data exists", true); 165 | return; 166 | } 167 | agc = true; 168 | } 169 | var row = SelectItemForm.GetSelectedRow(items, _data.Item2, _data.Item3, dataBoundItem[newColumn.DataPropertyName], agc); 170 | if (row != null) 171 | { 172 | dataBoundItem.BeginEdit(); 173 | dataBoundItem[newColumn.DataPropertyName] = row[_data.Item2]; 174 | dataBoundItem.EndEdit(); 175 | } 176 | } 177 | }; 178 | } 179 | else if (column.Mode == ColumnEditorMode.ComboBox) 180 | { 181 | var newColumn = new DataGridViewComboBoxColumn(); 182 | column.GeneratedDataGridViewColumn = newColumn; 183 | newColumn.DisplayStyleForCurrentCellOnly = true; 184 | newColumn.DisplayStyle = column.IsReadOnly ? DataGridViewComboBoxDisplayStyle.Nothing : DataGridViewComboBoxDisplayStyle.DropDownButton; 185 | newColumn.AutoComplete = true; 186 | if (column.IsNull) newColumn.DefaultCellStyle = new DataGridViewCellStyle() { DataSourceNullValue = DBNull.Value }; 187 | newColumn.SortMode = DataGridViewColumnSortMode.Automatic; 188 | newColumn.HeaderText = column.HeaderText; 189 | if (column.FillWeight.HasValue) 190 | { 191 | newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 192 | newColumn.FillWeight = column.FillWeight.Value; 193 | newColumn.MinimumWidth = column.HeaderText.Length * 10; 194 | if (newColumn.MinimumWidth < 50) newColumn.MinimumWidth = 50; 195 | } 196 | newColumn.ToolTipText = column.ColumnName; 197 | newColumn.DataPropertyName = column.ColumnName; 198 | newColumn.DataSource = column.DataSource; 199 | if (!string.IsNullOrWhiteSpace(column.ValueMember)) newColumn.ValueMember = column.ValueMember; 200 | if (!string.IsNullOrWhiteSpace(column.DisplayMember)) newColumn.DisplayMember = column.DisplayMember; 201 | newColumn.ReadOnly = column.IsReadOnly; 202 | dataGrid.Columns.Add(newColumn); 203 | if (column.FormatValueMethod != null) 204 | { 205 | newColumn.Tag = column.FormatValueMethod; 206 | dataGrid.CellFormatting += delegate (object sender, DataGridViewCellFormattingEventArgs e) 207 | { 208 | var _data = newColumn.Tag as FormatValueDelegate; 209 | if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) 210 | { 211 | var _value = _data.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); 212 | if (_value != null) 213 | { 214 | e.Value = _value; 215 | e.FormattingApplied = _value is string; 216 | } 217 | } 218 | }; 219 | } 220 | } 221 | } 222 | dataGrid.DataSource = DataSource; 223 | dataGrid.ResumeLayout(false); 224 | } 225 | 226 | #region Add Text and Check Columns 227 | 228 | /// 229 | /// Creating new TextBox column and adding it to the DataGridView 230 | /// 231 | /// DataGridView 232 | /// 233 | /// 234 | /// 235 | /// DataGridViewTextBoxColumn 236 | public static DataGridViewTextBoxColumn AddTextColumn(this DataGridView dataGrid, string DataPropertyName, string HeaderText = null, string ToolTipText = null) 237 | { 238 | DataGridViewTextBoxColumn result = new DataGridViewTextBoxColumn(); 239 | result.DataPropertyName = DataPropertyName; 240 | if (!string.IsNullOrEmpty(HeaderText)) result.HeaderText = HeaderText; 241 | if (!string.IsNullOrWhiteSpace(ToolTipText)) result.ToolTipText = ToolTipText; 242 | result.ReadOnly = true; 243 | result.SortMode = DataGridViewColumnSortMode.Automatic; 244 | dataGrid.Columns.Add(result); 245 | return result; 246 | } 247 | 248 | /// 249 | /// Creating new CheckBox column and adding it to the DataGridView 250 | /// 251 | /// DataGridView 252 | /// 253 | /// 254 | /// 255 | /// DataGridViewCheckBoxColumn 256 | public static DataGridViewCheckBoxColumn AddCheckColumn(this DataGridView dataGrid, string DataPropertyName, string HeaderText = null, string ToolTipText = null) 257 | { 258 | DataGridViewCheckBoxColumn result = new DataGridViewCheckBoxColumn(); 259 | result.DataPropertyName = DataPropertyName; 260 | if (!string.IsNullOrEmpty(HeaderText)) result.HeaderText = HeaderText; 261 | if (!string.IsNullOrWhiteSpace(ToolTipText)) result.ToolTipText = ToolTipText; 262 | result.ReadOnly = true; 263 | result.SortMode = DataGridViewColumnSortMode.Automatic; 264 | dataGrid.Columns.Add(result); 265 | return result; 266 | } 267 | 268 | #endregion 269 | 270 | /// 271 | /// Set the visualization style for the DataGridViewColumn based on prefered EditorDataStyle 272 | /// 273 | /// DataGridViewColumn 274 | /// Data visualization style 275 | private static void SetEditorDataStyle(DataGridViewColumn column, EditorDataStyle Style) 276 | { 277 | switch (Style) 278 | { 279 | case EditorDataStyle.Decimal: column.SetDecimalStyle(); break; 280 | case EditorDataStyle.Number: column.SetNumberStyle(); break; 281 | case EditorDataStyle.Money: column.SetMoneyStyle(); break; 282 | case EditorDataStyle.Percent: column.SetPercentStyle(); break; 283 | case EditorDataStyle.DateTime: column.SetDateTimeStyle(); break; 284 | case EditorDataStyle.Date: column.SetDateStyle(); break; 285 | } 286 | } 287 | 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /Examples/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | 123 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 124 | YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAADImlUWHRYTUw6Y29tLmFkb2Jl 125 | LnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQi 126 | Pz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENv 127 | cmUgNS4wLWMwNjEgNjQuMTQwOTQ5LCAyMDEwLzEyLzA3LTEwOjU3OjAxICAgICAgICAiPiA8cmRmOlJE 128 | RiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8 129 | cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20v 130 | eGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29t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F0CL64FhVGAnMLUnUHcS23h7vgmTllT1SKNt2SB 224 | kdMw+haB0TP0kcMeffCvgEpjjynbAzjvyuJ6sgBVR1mc7SWB0FgODyPzeBJfxNNkHuEPX8B0oXISY8eJ 225 | LYfa/bgcL+KwKVBea9T7Sw4IL4Qx9LgHYRtwodfpxnOnF2cfC9jfEaH+gzhg9OFCUMRBimpycexOWKw6 226 | A8srOyYyS0gvfMXM4goms3k4PF7sNkTRGt/Apcg3XAytojUi4mpyjc6C2lRqnMkmEmGaAHodLohrm9jY 227 | 3sE6UVzfgtX+Bvh0DnXaAK6Q/baoiLZYAU26IckV7+IEsYVzwP0a4eFxpKZymJxbRvztRzzrd+NBeAnm 228 | 2DzqbnqpuAh2wyM53sc3rkQf2Y2NvMfn2TwyCytIvpugthxY3gFWqcCWmAW75kFBKgfdGX+1gO5+l9lC 229 | lrv7nbD0OfDS7YV5aFQqKBIt0Qx+UBR/83LQxfNVCxDUTCNIi+b4HLoTWVgTczBHZohpdMdKsSs4JeXU 230 | EmC7tKXf+pPIN7JF06AOJNqi0/hFcZvIUa+tIcBVK9ETm5ZH1WOOhloO/vU2aoHnymVlqEzCd+l1kjq3 231 | yB1JsWLM13gOz5XLqtBMlO7F/8ma/wA9PU0+6NmRAAAAAABJRU5ErkJggg== 232 | 233 | 234 | -------------------------------------------------------------------------------- /Examples/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | False 122 | 123 | 124 | 17, 17 125 | 126 | 127 | 128 | 129 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 130 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAFKSURBVDhPYxi84O4C9v+35nH+vzqH6//FGbz/ocLEg+tA 131 | jX8eNf7/87Dh/8nJAqQbcH46L9yAgz0ipBtwfJIgUHPd/z8Pqv7vaBcnbMClmTz/z07l+38SqPFIv9D/ 132 | fd0iQM3l///eK/q/vkHm/6oauf9LKxX/zy9V/j+rSBXTwFNAf/55WA/UVAvElf//3CsB4rz/f+9m/v97 133 | J/n/39tx///djADikP+TcjQxDTjUKwx27t/7pUCNBUCN2UCNqUCNCf//3YoGagz7/+9G0P9/1/3+d6Xp 134 | Yhqws13i/5Zmqf/rwM6V/7+kQvH/31sxQI3h/6fmafyfkKX1vztD9397qv7/5kRDwmEyG+hPkHP/3Qj4 135 | 35OhQ1gDOgD5898NfyD2+9+arE+6Ad3pumD/gnB9nBHpBrQkGfxviDf8XxNr/L8y2oR0A+gEGBgAJCPY 136 | nnX8iGkAAAAASUVORK5CYII= 137 | 138 | 139 | 140 | 141 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 142 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAFvSURBVDhPtZBNKMNhHMd3Vd5K7eKCWjkgk7yEZDKksciE 143 | yMwkBw6LhHZxcCDlQg64SA4kJeVE4jRv89qaWn8tUtoF/7g8H2Ootb+x4nt56nm+38/v+/xUfyJcJ9Bt 144 | BMcOH1eRiZV5RGcVwqyHrfWwELweWJoJ9rC2AL0mRLse0VEBcxOKkLeGwlwGIz2h75w6ApC6b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Yxg6ILz9wX8ok3QQ3/3gf3DDNfIMiO95+H/p 166 | /v///asvkG5ARPt9sObMWf//e5WeIM2A0NZ7YM2t64C2d/7975J/gHgDglvu/l+09///DqDmjDk//9vV 167 | /fxvn7GdNBfYFd/+nz7n93//rm//dQrf/bdIWE96GOinnP9vUvTiv0rWp//GkctINwAEDJJO/JdN+/pf 168 | N3geeQaAgH7q5f8avtPINwAEVDwmUGbAYAUMDADQFGCYBLpQVQAAAABJRU5ErkJggg== 169 | 170 | 171 | 172 | 173 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 174 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAACjSURBVDhPYxh8oHDW8/9QJnkgd+az/wnd98g3JGPK0//z 175 | 9v/+n9B1hzxDEnqe/J+979f/zq1//7uVXibdkMiuR/+nbPv1v2Tp3/8J0//+t8k9S5ohgc0P/7eufQ/W 176 | bFzy5b909LX/xpHLiDfEo+r+/5K57+CaFV16SHOBfend/4Etz8jTDAIWeXf+2xRcIU8zCBhm3SZfMwjo 177 | pN0gX/NQBAwMAKB+X6AHNEI4AAAAAElFTkSuQmCC 178 | 179 | 180 | 181 | 182 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 183 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAEsSURBVDhPYxhcoHDW8/9QJgYAyTUteP4/c+JjnGoYcmc+ 184 | +5/QfQ+rApDcqiPv/4e3P8BtQMaUp//n7f/9P6HrDoYikNzCfR/+Bzdcw21AQs+T/7P3/frfufXvf7fS 185 | yygKQXLTtrz/7199AbcBkV2P/k/Z9ut/ydK//xOm//1vk3sWrhgk17v6w3+v0hO4DQhsfvi/de17sGbj 186 | ki//paOv/TeOXAbWAJKrm//uv0v+AdwGeFTd/18y9x1cs6JLD1wxSC5/2pv/9hnbcRtgX3r3f2DLMwzN 187 | IACSy578+r9FwnrcBljk3flvU3AFQzMIgORS+1/DvYQVGGbdxqoZBEByYS0v/+sGz8NtgE7aDZySIDm/ 188 | 6of/NXyn4TYAH3DKvfJfxWMCGEOFBgVgYAAAvtG/s7kMTpwAAAAASUVORK5CYII= 189 | 190 | 191 | 192 | 223, 17 193 | 194 | 195 | 196 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 197 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAFKSURBVDhPYxi84O4C9v+35nH+vzqH6//FGbz/ocLEg+tA 198 | jX8eNf7/87Dh/8nJAqQbcH46L9yAgz0ipBtwfJIgUHPd/z8Pqv7vaBcnbMClmTz/z07l+38SqPFIv9D/ 199 | fd0iQM3l///eK/q/vkHm/6oauf9LKxX/zy9V/j+rSBXTwFNAf/55WA/UVAvElf//3CsB4rz/f+9m/v97 200 | J/n/39tx///djADikP+TcjQxDTjUKwx27t/7pUCNBUCN2UCNqUCNCf//3YoGagz7/+9G0P9/1/3+d6Xp 201 | Yhqws13i/5Zmqf/rwM6V/7+kQvH/31sxQI3h/6fmafyfkKX1vztD9397qv7/5kRDwmEyG+hPkHP/3Qj4 202 | 35OhQ1gDOgD5898NfyD2+9+arE+6Ad3pumD/gnB9nBHpBrQkGfxviDf8XxNr/L8y2oR0A+gEGBgAJCPY 203 | nnX8iGkAAAAASUVORK5CYII= 204 | 205 | 206 | 207 | 208 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 209 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAFvSURBVDhPtZBNKMNhHMd3Vd5K7eKCWjkgk7yEZDKksciE 210 | yMwkBw6LhHZxcCDlQg64SA4kJeVE4jRv89qaWn8tUtoF/7g8H2Ootb+x4nt56nm+38/v+/xUfyJcJ9Bt 211 | BM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IArs4c6QAAAARnQU1BAACxjwv8 232 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAC2SURBVDhPYxg6ILz9wX8ok3QQ3/3gf3DDNfIMiO95+H/p 233 | /v///asvkG5ARPt9sObMWf//e5WeIM2A0NZ7YM2t64C2d/7975J/gHgDglvu/l+09///DqDmjDk//9vV 234 | /fxvn7GdNBfYFd/+nz7n93//rm//dQrf/bdIWE96GOinnP9vUvTiv0rWp//GkctINwAEDJJO/JdN+/pf 235 | N3geeQaAgH7q5f8avtPINwAEVDwmUGbAYAUMDADQFGCYBLpQVQAAAABJRU5ErkJggg== 236 | 237 | 238 | 239 | 240 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 241 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAACjSURBVDhPYxh8oHDW8/9QJnkgd+az/wnd98g3JGPK0//z 242 | 9v/+n9B1hzxDEnqe/J+979f/zq1//7uVXibdkMiuR/+nbPv1v2Tp3/8J0//+t8k9S5ohgc0P/7eufQ/W 243 | bFzy5b909LX/xpHLiDfEo+r+/5K57+CaFV16SHOBfend/4Etz8jTDAIWeXf+2xRcIU8zCBhm3SZfMwjo 244 | pN0gX/NQBAwMAKB+X6AHNEI4AAAAAElFTkSuQmCC 245 | 246 | 247 | 248 | 249 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 250 | YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAAEsSURBVDhPYxhcoHDW8/9QJgYAyTUteP4/c+JjnGoYcmc+ 251 | +5/QfQ+rApDcqiPv/4e3P8BtQMaUp//n7f/9P6HrDoYikNzCfR/+Bzdcw21AQs+T/7P3/frfufXvf7fS 252 | yygKQXLTtrz/7199AbcBkV2P/k/Z9ut/ydK//xOm//1vk3sWrhgk17v6w3+v0hO4DQhsfvi/de17sGbj 253 | ki//paOv/TeOXAbWAJKrm//uv0v+AdwGeFTd/18y9x1cs6JLD1wxSC5/2pv/9hnbcRtgX3r3f2DLMwzN 254 | IACSy578+r9FwnrcBljk3flvU3AFQzMIgORS+1/DvYQVGGbdxqoZBEByYS0v/+sGz8NtgE7aDZySIDm/ 255 | 6of/NXyn4TYAH3DKvfJfxWMCGEOFBgVgYAAAvtG/s7kMTpwAAAAASUVORK5CYII= 256 | 257 | 258 | 259 | False 260 | 261 | 262 | False 263 | 264 | 265 | 17, 60 266 | 267 | 268 | 532, 17 269 | 270 | 271 | 416, 17 272 | 273 | 274 | 770, 17 275 | 276 | 277 | 995, 17 278 | 279 | -------------------------------------------------------------------------------- /Source/Forms/SelectItemForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Windows.Forms; 7 | 8 | namespace CBComponents.Forms 9 | { 10 | using CBComponents; 11 | 12 | /// 13 | /// This form is using for selecting row from Collections or DataTable 14 | /// 15 | public sealed class SelectItemForm : Form 16 | { 17 | public class ColumnDefinition 18 | { 19 | public string HeaderText; 20 | public string DataPropertyName; 21 | public DataGridViewContentAlignment ContentAlignment; 22 | public float? FillWeight; 23 | public SqlDbType DataPropertyType; 24 | } 25 | 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static ColumnDefinition CreateColumnDefinition(string HeaderText, string DataPropertyName, DataGridViewContentAlignment ContentAlignment = DataGridViewContentAlignment.NotSet, float? FillWeight = null, SqlDbType DataPropertyType = SqlDbType.NVarChar) 36 | { 37 | var result = new ColumnDefinition(); 38 | result.HeaderText = HeaderText; 39 | result.DataPropertyName = DataPropertyName; 40 | result.ContentAlignment = ContentAlignment; 41 | result.FillWeight = FillWeight; 42 | result.DataPropertyType = DataPropertyType; 43 | return result; 44 | } 45 | 46 | public static T GetSelectedRow(IEnumerable DataSource, params SelectItemForm.ColumnDefinition[] Columns) 47 | { 48 | return SelectItemForm.GetSelectedRow(null, null, DataSource, default(T), Columns); 49 | } 50 | 51 | public static T GetSelectedRow(IEnumerable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) 52 | { 53 | return SelectItemForm.GetSelectedRow(null, null, DataSource, SelectedRow, Columns); 54 | } 55 | 56 | public static T GetSelectedRow(string Text, IEnumerable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) 57 | { 58 | return SelectItemForm.GetSelectedRow(Text, null, DataSource, SelectedRow, Columns); 59 | } 60 | 61 | public static T GetSelectedRow(string Text, string HeaderText, IEnumerable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) 62 | { 63 | if (DataSource == null || DataSource.Count() == 0) return default(T); 64 | if (DataSource.Count() == 1) return DataSource.First(); 65 | using (var form = new SelectItemForm(new SortableBindingList(DataSource), SelectedRow == null ? DataSource.First() : SelectedRow, Columns)) 66 | { 67 | if (!string.IsNullOrWhiteSpace(Text)) form.Text = Text; 68 | if (!string.IsNullOrWhiteSpace(HeaderText)) form.SetHeaderText(HeaderText); 69 | 70 | if (FormServices.ShowFormDialog(form) == DialogResult.OK && form.bindingSource.Current is T) 71 | return (T)form.bindingSource.Current; 72 | else return default(T); 73 | } 74 | } 75 | 76 | public static T GetSelectedRow(DataTable DataSource, params SelectItemForm.ColumnDefinition[] Columns) 77 | where T : DataRow 78 | { 79 | return SelectItemForm.GetSelectedRow(DataSource, null, Columns); 80 | } 81 | 82 | public static T GetSelectedRow(DataTable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) 83 | where T : DataRow 84 | { 85 | if (DataSource == null || DataSource.Rows.Count == 0) return null; 86 | if (DataSource.Rows.Count == 1) return DataSource.Rows[0] as T; 87 | using (var form = new SelectItemForm(DataSource, SelectedRow ?? DataSource.Rows[0], Columns)) 88 | if (FormServices.ShowFormDialog(form) == DialogResult.OK) 89 | { 90 | var drv = form.bindingSource.Current as DataRowView; 91 | if (drv != null) return drv.Row as T; 92 | else return form.bindingSource.Current as T; 93 | } 94 | else return null; 95 | } 96 | 97 | internal static DataRow GetSelectedRow(object DataSource, string ValueMember = null, string DisplayMember = null, object SelectedValue = null, bool AutoGenerateColumns = false) 98 | { 99 | SelectItemForm.ColumnDefinition[] Columns = null; 100 | if (!AutoGenerateColumns && !string.IsNullOrWhiteSpace(ValueMember) && !string.IsNullOrWhiteSpace(DisplayMember)) 101 | { 102 | Columns = new SelectItemForm.ColumnDefinition[] { 103 | SelectItemForm.CreateColumnDefinition("Value", ValueMember), 104 | SelectItemForm.CreateColumnDefinition("Name", DisplayMember, FillWeight: 100), 105 | }; 106 | } 107 | using (var form = new SelectItemForm(DataSource, SelectedValue, Columns)) 108 | { 109 | try 110 | { 111 | var pos = form.bindingSource.Find(ValueMember, SelectedValue); 112 | if (pos >= 0) form.bindingSource.Position = pos; 113 | } 114 | catch { } 115 | if (FormServices.ShowFormDialog(form) == DialogResult.OK) 116 | { 117 | var drv = form.bindingSource.Current as DataRowView; 118 | if (drv != null) return drv.Row; 119 | else return form.bindingSource.Current as DataRow; 120 | } 121 | else return null; 122 | } 123 | } 124 | 125 | /// 126 | /// 127 | /// 128 | /// 129 | /// 130 | /// 131 | /// 132 | public static void ShowData(object DataSource, string Text, params SelectItemForm.ColumnDefinition[] Columns) 133 | { 134 | SelectItemForm.ShowData(DataSource, Text, null, Columns); 135 | } 136 | 137 | /// 138 | /// 139 | /// 140 | /// 141 | /// 142 | /// 143 | /// 144 | /// 145 | public static void ShowData(object DataSource, string Text, string HeaderText, params SelectItemForm.ColumnDefinition[] Columns) 146 | { 147 | using (var form = new SelectItemForm(DataSource, null, Columns)) 148 | { 149 | if (!string.IsNullOrWhiteSpace(Text)) form.Text = Text; 150 | if (!string.IsNullOrWhiteSpace(HeaderText)) form.SetHeaderText(HeaderText); 151 | FormServices.ShowFormDialog(form); 152 | } 153 | } 154 | 155 | #region Form creation 156 | 157 | private BindingSource bindingSource; 158 | public readonly DataGridView dataGrid; 159 | private PromptedTextBox searchTextBox; 160 | private Label headerLabel; 161 | private Label footerLabel; 162 | private Button btnOk; 163 | private Button btnClose; 164 | 165 | /// 166 | /// 167 | /// 168 | /// 169 | /// 170 | /// 171 | /// 172 | public static SelectItemForm CreateFormWithoutColumns(object DataSource, string Text = null, string HeaderText = null) 173 | { 174 | var form = new SelectItemForm(DataSource, null, new SelectItemForm.ColumnDefinition[] { null }); 175 | if (!string.IsNullOrWhiteSpace(Text)) form.Text = Text; 176 | if (!string.IsNullOrWhiteSpace(HeaderText)) form.SetHeaderText(HeaderText); 177 | return form; 178 | } 179 | 180 | /// 181 | /// 182 | /// 183 | /// 184 | /// 185 | /// 186 | private SelectItemForm(object DataSource, object SelectedItem, params SelectItemForm.ColumnDefinition[] Columns) 187 | { 188 | // setting up the bindingSource 189 | this.bindingSource = new BindingSource(); 190 | this.bindingSource.DataSource = DataSource; 191 | if (SelectedItem != null) 192 | { 193 | this.bindingSource.MoveLast(); 194 | while (this.bindingSource.Position > 0) 195 | { 196 | if (this.bindingSource.Current == SelectedItem) break; 197 | else 198 | { 199 | var drv = this.bindingSource.Current as DataRowView; 200 | if (drv != null && drv.Row == SelectedItem) break; 201 | if (drv != null && SelectedItem is DataRow && drv.Row.ItemArray.SequenceEqual(((DataRow)SelectedItem).ItemArray)) break; 202 | } 203 | this.bindingSource.MovePrevious(); 204 | } 205 | } 206 | 207 | // Setting up the controls 208 | this.dataGrid = new DataGridView(); 209 | if (this.bindingSource.SupportsFiltering) this.searchTextBox = new PromptedTextBox(); 210 | this.headerLabel = new Label(); 211 | this.footerLabel = new Label(); 212 | this.btnClose = new Button(); 213 | if (SelectedItem != null) this.btnOk = new Button(); 214 | var mainPanel = new TableLayoutPanel(); 215 | 216 | mainPanel.SuspendLayout(); 217 | this.SuspendLayout(); 218 | // 219 | // mainPanel 220 | // 221 | mainPanel.ColumnCount = 4; 222 | mainPanel.ColumnStyles.Add(new ColumnStyle()); 223 | mainPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); 224 | mainPanel.ColumnStyles.Add(new ColumnStyle()); 225 | mainPanel.ColumnStyles.Add(new ColumnStyle()); 226 | if (this.bindingSource.SupportsFiltering) mainPanel.Controls.Add(this.searchTextBox, 2, 0); 227 | mainPanel.Controls.Add(this.dataGrid, 0, 1); 228 | mainPanel.Controls.Add(this.headerLabel, 0, 0); 229 | mainPanel.Controls.Add(this.footerLabel, 0, 2); 230 | mainPanel.Controls.Add(this.btnClose, 3, 2); 231 | if (SelectedItem != null) mainPanel.Controls.Add(this.btnOk, 2, 2); 232 | mainPanel.Dock = DockStyle.Fill; 233 | mainPanel.RowCount = 3; 234 | mainPanel.RowStyles.Add(new RowStyle()); 235 | mainPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); 236 | mainPanel.RowStyles.Add(new RowStyle()); 237 | mainPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); 238 | mainPanel.Padding = new Padding(6); 239 | // 240 | // searchTextBox 241 | // 242 | if (this.bindingSource.SupportsFiltering) 243 | { 244 | this.searchTextBox.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; 245 | mainPanel.SetColumnSpan(this.searchTextBox, 2); 246 | this.searchTextBox.FocusSelect = true; 247 | this.searchTextBox.PromptForeColor = SystemColors.ControlDark; 248 | this.searchTextBox.PromptText = "searching..."; 249 | this.searchTextBox.Size = new Size(150, 20); 250 | this.searchTextBox.TabIndex = 1; 251 | this.searchTextBox.TextChanged += delegate 252 | { 253 | string _txt = this.searchTextBox.Text.Trim(); 254 | if (string.IsNullOrEmpty(_txt)) this.bindingSource.RemoveFilter(); 255 | else this.bindingSource.Filter = RowFilterBuilder.BuildColumnFilter(_txt, this.dataGrid).Trim(); 256 | foreach (DataGridViewRow row in this.dataGrid.SelectedRows) row.Selected = false; 257 | if (this.dataGrid.Rows.Count > 0) this.dataGrid.Rows[0].Selected = true; 258 | }; 259 | } 260 | // 261 | // dataGrid 262 | // 263 | mainPanel.SetColumnSpan(this.dataGrid, 4); 264 | this.dataGrid.Dock = DockStyle.Fill; 265 | this.dataGrid.TabIndex = 0; 266 | this.dataGrid.PrepareStyleForShowingData(); 267 | this.dataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; 268 | this.dataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; 269 | if (Columns == null || Columns.Length == 0) this.dataGrid.AutoGenerateColumns = true; 270 | else 271 | { 272 | this.dataGrid.AutoGenerateColumns = false; 273 | if (Columns[0] != null) 274 | foreach (var _column in Columns) 275 | { 276 | DataGridViewColumn _c; 277 | if (_column.DataPropertyType == SqlDbType.Bit) _c = this.dataGrid.AddCheckColumn(_column.DataPropertyName, _column.HeaderText); 278 | else if (_column.DataPropertyType == SqlDbType.Date) _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText).SetDateStyle(); 279 | else if (_column.DataPropertyType == SqlDbType.DateTime) _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText).SetDateTimeWithSecondsStyle(); 280 | else if (_column.DataPropertyType == SqlDbType.Int || _column.DataPropertyType == SqlDbType.TinyInt) _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText).SetNumberStyle(); 281 | else if (_column.DataPropertyType == SqlDbType.Decimal || _column.DataPropertyType == SqlDbType.Float) _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText).SetDecimalStyle(); 282 | else if (_column.DataPropertyType == SqlDbType.Money) _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText).SetMoneyStyle(); 283 | else _c = this.dataGrid.AddTextColumn(_column.DataPropertyName, _column.HeaderText); 284 | if (_column.ContentAlignment != DataGridViewContentAlignment.NotSet) _c.SetStyles(50, _column.ContentAlignment); 285 | if (_column.FillWeight.HasValue) _c.SetAutoSizeFillStyle(100, _column.FillWeight.Value); 286 | } 287 | } 288 | if (SelectedItem == null) 289 | this.dataGrid.DataBindingComplete += delegate 290 | { 291 | foreach (DataGridViewRow row in this.dataGrid.SelectedRows) 292 | row.Selected = false; 293 | }; 294 | else 295 | { 296 | this.dataGrid.DoubleClick += delegate { this.AcceptButton.PerformClick(); }; 297 | this.dataGrid.KeyDown += delegate (object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return) { e.Handled = true; this.AcceptButton.PerformClick(); } }; 298 | } 299 | this.dataGrid.DataSource = this.bindingSource; 300 | // 301 | // headerLabel 302 | // 303 | this.headerLabel.Anchor = AnchorStyles.Left; 304 | mainPanel.SetColumnSpan(this.headerLabel, 2); 305 | this.headerLabel.AutoSize = true; 306 | this.headerLabel.ForeColor = SystemColors.ControlDarkDark; 307 | this.headerLabel.TextAlign = ContentAlignment.MiddleLeft; 308 | this.headerLabel.Visible = false; 309 | // 310 | // footerLabel 311 | // 312 | this.footerLabel.Anchor = AnchorStyles.Left; 313 | mainPanel.SetColumnSpan(this.footerLabel, 2); 314 | this.footerLabel.AutoSize = true; 315 | this.footerLabel.ForeColor = SystemColors.ControlDarkDark; 316 | this.headerLabel.TextAlign = ContentAlignment.MiddleLeft; 317 | this.footerLabel.Visible = false; 318 | // 319 | // btnOk 320 | // 321 | if (SelectedItem != null) 322 | { 323 | this.btnOk.Anchor = AnchorStyles.Right; 324 | this.btnOk.DialogResult = DialogResult.OK; 325 | this.btnOk.Size = new Size(80, 25); 326 | this.btnOk.TabIndex = 3; 327 | this.btnOk.Text = "Select"; 328 | this.btnOk.Margin = new Padding(3, 9, 3, 6); 329 | } 330 | // 331 | // btnClose 332 | // 333 | this.btnClose.Anchor = AnchorStyles.Right; 334 | this.btnClose.DialogResult = DialogResult.Cancel; 335 | this.btnClose.Size = new Size(80, 25); 336 | this.btnClose.TabIndex = 4; 337 | this.btnClose.Text = SelectedItem != null ? "Cancel" : "Close"; 338 | this.btnClose.Margin = new Padding(3, 9, 3, 6); 339 | // 340 | // SelectItemForm 341 | // 342 | this.AutoScaleDimensions = new SizeF(6F, 13F); 343 | this.AutoScaleMode = AutoScaleMode.Font; 344 | this.AcceptButton = SelectedItem != null ? this.btnOk : this.btnClose; 345 | this.CancelButton = this.btnClose; 346 | this.ClientSize = new Size(624, 362); 347 | this.Controls.Add(mainPanel); 348 | this.MaximizeBox = false; 349 | this.MinimizeBox = false; 350 | this.MinimumSize = new Size(320, 200); 351 | this.ShowIcon = false; 352 | this.ShowInTaskbar = false; 353 | this.StartPosition = FormStartPosition.CenterScreen; 354 | this.Text = SelectedItem != null ? "Select a row" : "Data"; 355 | mainPanel.ResumeLayout(false); 356 | mainPanel.PerformLayout(); 357 | this.ResumeLayout(false); 358 | } 359 | 360 | protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 361 | { 362 | if (this.searchTextBox != null && !this.searchTextBox.Focused && this.searchTextBox.Visible && (keyData >= Keys.A && keyData <= Keys.Z || keyData >= Keys.D0 && keyData <= Keys.D9)) 363 | { 364 | this.searchTextBox.Select(); 365 | return true; 366 | } 367 | else return base.ProcessCmdKey(ref msg, keyData); 368 | } 369 | 370 | protected override void OnLoad(EventArgs e) 371 | { 372 | // width of form without scroll 373 | var nWidth = this.dataGrid.PreferredSize.Width + 2 * this.dataGrid.Left + 1; 374 | var screenWidth = 2 * Screen.PrimaryScreen.WorkingArea.Width / 3; // 2/3 is maximun 375 | if (screenWidth < nWidth) nWidth = screenWidth; 376 | if (this.MinimumSize.Width > nWidth) nWidth = this.MinimumSize.Width; // if (480 > nWidth) nWidth = 480; 377 | this.Left -= (nWidth - this.Width) / 2; 378 | this.Width = nWidth; 379 | base.OnLoad(e); 380 | // Hiding the identification columns 381 | if (this.dataGrid.AutoGenerateColumns && this.dataGrid.Columns.Count > 0 && this.dataGrid.Columns[0].DataPropertyName.EndsWith("ID")) 382 | this.dataGrid.Columns[0].Visible = false; 383 | } 384 | 385 | protected override void OnShown(EventArgs e) 386 | { 387 | base.OnShown(e); 388 | if (!this.footerLabel.Visible && this.bindingSource.Count > 0) 389 | { 390 | this.footerLabel.Text = string.Format("Rows: {0}", this.bindingSource.Count); 391 | this.footerLabel.Visible = true; 392 | } 393 | } 394 | 395 | #endregion 396 | 397 | /// 398 | /// Setting thext in the header 399 | /// 400 | /// Prefered text 401 | public void SetHeaderText(string Text) 402 | { 403 | if (!string.IsNullOrWhiteSpace(Text)) 404 | { 405 | this.headerLabel.Text = Text; 406 | this.headerLabel.Visible = true; 407 | } 408 | } 409 | 410 | /// 411 | /// Setting thext in the footer 412 | /// 413 | /// Prefered text 414 | public void SetFooterText(string Text) 415 | { 416 | if (!string.IsNullOrWhiteSpace(Text)) 417 | { 418 | this.footerLabel.Text = Text; 419 | this.footerLabel.Visible = true; 420 | } 421 | } 422 | 423 | } 424 | } --------------------------------------------------------------------------------