├── 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 | 
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 | YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAADImlUWHRYTUw6Y29tLmFkb2Jl
125 | LnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQi
126 | Pz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENv
127 | cmUgNS4wLWMwNjEgNjQuMTQwOTQ5LCAyMDEwLzEyLzA3LTEwOjU3OjAxICAgICAgICAiPiA8cmRmOlJE
128 | RiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8
129 | cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20v
130 | eGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxu
131 | czpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1w
132 | OkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1LjEgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJ
133 | RD0ieG1wLmlpZDpEQzAwNTlDNjEwNzkxMUUzQTNGMzhDRTM1RjU4MEYyNiIgeG1wTU06RG9jdW1lbnRJ
134 | RD0ieG1wLmRpZDpEQzAwNTlDNzEwNzkxMUUzQTNGMzhDRTM1RjU4MEYyNiI+IDx4bXBNTTpEZXJpdmVk
135 | RnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkRDMDA1OUM0MTA3OTExRTNBM0YzOENFMzVGNTgw
136 | RjI2IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkRDMDA1OUM1MTA3OTExRTNBM0YzOENFMzVGNTgw
137 | RjI2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQg
138 | ZW5kPSJyIj8+WlstlQAAAkdJREFUOE+dk81PE1EUxSdxIWx0qa7duuP/UUjYSFy6URSUoCF8tU7BpJB+
139 | 0BFbCoKKgqCoYIkFI1CqAUFEgRgstB1asFIIP++bUkK3nOTkzn1zz3lv3p2rXagdSp6pGqC48gVFQhWL
140 | K18W5rckP0ZVL7oFTUElJ8HZ6gEsA7WDwpQJ08LZbahu8VhxZgsiO3C7zaC/fRjX5TqeOV9Z9cXVg4UG
141 | kRRERTS3C7XOR8xL/JIRw33wlNbDepIDoYqB8ga0mteFBjUP3dxzdlDn6qTR20W9N8B9XwBvWQPEU8S9
142 | I2wI4543Vt5dYS80WJLdfsiuqwfQ7AnwW9aMskZI7GB2hkj4hY+Fxgf21xNikqb3ets7Td20woqI1/bk
143 | hPKs+7pobdFJ7qRZfj7OdnCCVPcEW8Ew2ZhJrG0ItjJ4r+kcGTQ53dhdBo4OP60Oncy/v4Q+hhmdDLM6
144 | 9JlM7xTZDRG7htntDmNU2NQnlBwZyKGQS6en7ynZvSzTM1HhLFORKJ+is+z/MdmQTmTkFP6rIr47nLuD
145 | vIE0ALkG/IEulpd/svh9iYXFRebmv7FpmkQGx0j3TeIpb7bqT1UdtjFv4HS7ae8wMII9OHSdWGyTldU1
146 | EmaS0dA4X8XMfaWRdn+nVV8kf2SBgYI0wIK/5wl2u41UKs2YiOfmF2i2NR2+zUHpLIN8G4/D8Pms+HZk
147 | BF2MHthyxz4OpbMMTjoLSmcZnLsRfJ+fxtM3cxNYJNOYZ34C1bp6r+pU/fk7/b8sA8FFYckJeEnTNO0/
148 | n8beudCA+c4AAAAASUVORK5CYII=
149 |
150 |
151 |
152 |
153 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
154 | YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAABxUlEQVQ4T6VT2S5DURS9Ymyb
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