diff --git a/NumericUpDown Image.png b/NumericUpDown Image.png new file mode 100644 index 0000000..3053a5c Binary files /dev/null and b/NumericUpDown Image.png differ diff --git a/README.md b/README.md index a49ecad..16728d5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,79 @@ -# How-to-implement-NumericUpDown-inside-SfDataGrid-using-Custom-Column-support. -How to implement NumericUpDown inside SfDataGrid using Custom Column support. +# How to implement NumericUpDown inside SfDataGrid using Custom Column support. + +To achieve the requirement of implementing a NumericUpDown inside an SfDataGrid column, follow these steps: + +**Step 1** : Create a custom column by overriding a new class derived from the GridColumn class. + + ```C# + public class NumericUpDownExtColumn : GridColumn + { + public NumericUpDownExtColumn() + { + SetCellType("NumericUpDown"); + } + + } + ``` + +**Step 2** : After creating a custom column, you need to create a renderer for the custom column. You can create a custom renderer by deriving from the GridCellRendererBase class. + +**Step 3** : In the OnRender method, you can create a NumericUpDown control. Within this method, initialize the properties for the NumericUpDown control, and finally, add the declared control into the DataGrid TableControl. + +You can add any other controls in the OnRender method by following this procedure based on your needs. + + + ```C# + public class NumericUpDownCellRenderer : GridCellRendererBase + { + public NumericUpDownCellRenderer(SfDataGrid dataGrid) + { + DataGrid = dataGrid; + IsInEditing = false; + } + protected SfDataGrid DataGrid { get; set; } + + protected override void OnRender(Graphics graphics, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) + { + var NumericUpDownExtControl = new NumericUpDown(); + NumericUpDownExtControl.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; + NumericUpDownExtControl.Value =Convert.ToDecimal(cellValue); + NumericUpDownExtControl.Increment = new decimal(new int[] { 5, 0, 0, 0 }); + NumericUpDownExtControl.Minimum = new decimal(new int[] { 0, 0, 0, 0 }); + NumericUpDownExtControl.Maximum = new decimal(new int[] { 40, 0, 0, 0 }); + NumericUpDownExtControl.Font = new Font(NumericUpDownExtControl.Font.FontFamily, 14); + NumericUpDownExtControl.Text = cellValue ?? string.Empty; + NumericUpDownExtControl.Size = cellRect.Size; + NumericUpDownExtControl.Location = cellRect.Location; + DataGrid.GetTopLevelParentDataGrid().TableControl.Controls.Add(NumericUpDownExtControl); + } + } + ``` + +**Step 4** : Then you can add the previously created custom renderer to the SfDataGrid.CellRenderers collection. + + + ```C# + public Form1() + { + InitializeComponent(); + this.sfDataGrid1.CellRenderers.Add("NumericUpDown", new NumericUpDownCellRenderer(sfDataGrid1)); + } + ``` + +**Step 5** : At last, finally, you can define the custom column in SfDataGrid. + + + ```C# + public Form1() + { + InitializeComponent(); + this.sfDataGrid1.Columns.Add(new NumericUpDownExtColumn() { MappingName = "NumericUpDown", HeaderText = "NumericUpDown"}); + } + ``` + +By following the above code, the output image is as referenced below. + + + ![NumericUpDown_Image.png](https://support.syncfusion.com/kb/agent/attachment/article/15707/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjIwNzUxIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.yG2J64WnfEu5VJbuOnqjv_4Po3p_Ce82_OS9tDfBzuw) + +Take a moment to peruse the [Winforms - DataGrid Custom Column Support UG Documentation](https://help.syncfusion.com/windowsforms/datagrid/columntypes#custom-column-support), to learn more about Custom Column support with examples. \ No newline at end of file diff --git a/SfDataGridDemo/SfDatagridDemo.sln b/SfDataGridDemo/SfDatagridDemo.sln new file mode 100644 index 0000000..72a18f0 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32922.545 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDatagridDemo", "SfDatagridDemo\SfDatagridDemo.csproj", "{99A85163-E55E-4123-8981-E23545B8580E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug-Xml|Any CPU = Debug-Xml|Any CPU + Release|Any CPU = Release|Any CPU + Release-Xml|Any CPU = Release-Xml|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {99A85163-E55E-4123-8981-E23545B8580E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Debug-Xml|Any CPU.ActiveCfg = Debug|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Debug-Xml|Any CPU.Build.0 = Debug|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Release|Any CPU.Build.0 = Release|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU + {99A85163-E55E-4123-8981-E23545B8580E}.Release-Xml|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E943C4E4-600F-4348-8CE2-6AA90A0A6684} + EndGlobalSection +EndGlobal diff --git a/SfDataGridDemo/SfDatagridDemo/App.config b/SfDataGridDemo/SfDatagridDemo/App.config new file mode 100644 index 0000000..8d23437 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/SfDataGridDemo/SfDatagridDemo/Form1.Designer.cs b/SfDataGridDemo/SfDatagridDemo/Form1.Designer.cs new file mode 100644 index 0000000..d264996 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Form1.Designer.cs @@ -0,0 +1,74 @@ + +namespace SfDatagridDemo +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.sfDataGrid1 = new Syncfusion.WinForms.DataGrid.SfDataGrid(); + ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid1)).BeginInit(); + this.SuspendLayout(); + // + // sfDataGrid1 + // + this.sfDataGrid1.AccessibleName = "Table"; + this.sfDataGrid1.Location = new System.Drawing.Point(0, 0); + this.sfDataGrid1.Name = "sfDataGrid1"; + this.sfDataGrid1.PreviewRowHeight = 42; + this.sfDataGrid1.Size = new System.Drawing.Size(1600, 2450); + this.sfDataGrid1.TabIndex = 0; + this.sfDataGrid1.Text = "sfDataGrid1"; + // + // button1 + // + //this.button1.Location = new System.Drawing.Point(625, 27); + //this.button1.Name = "button1"; + //this.button1.Size = new System.Drawing.Size(124, 36); + //this.button1.TabIndex = 1; + //this.button1.Text = "Select"; + //this.button1.UseVisualStyleBackColor = true; + //this.button1.Click += new System.EventHandler(this.button1_Click); + //// + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.sfDataGrid1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Syncfusion.WinForms.DataGrid.SfDataGrid sfDataGrid1; + } +} + diff --git a/SfDataGridDemo/SfDatagridDemo/Form1.cs b/SfDataGridDemo/SfDatagridDemo/Form1.cs new file mode 100644 index 0000000..bf76377 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Form1.cs @@ -0,0 +1,41 @@ +using SfDatagridDemo.Renderer; +using Syncfusion.WinForms.DataGrid; +using Syncfusion.WinForms.DataGrid.Enums; +using Syncfusion.WinForms.DataGrid.Renderers; +using Syncfusion.WinForms.DataGrid.Styles; +using Syncfusion.WinForms.GridCommon.ScrollAxis; +using Syncfusion.WinForms.Input; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SfDatagridDemo +{ + public partial class Form1 : Form + { + ViewModel viewModel; + public Form1() + { + InitializeComponent(); + sfDataGrid1.AutoGenerateColumns = false; + + viewModel = new ViewModel(); + this.sfDataGrid1.AllowEditing = true; + sfDataGrid1.DataSource = viewModel.OrdersListDetails; + this.sfDataGrid1.CellRenderers.Add("NumericUpDown", new NumericUpDownCellRenderer(sfDataGrid1)); + this.sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "OrderID", HeaderText = "Order ID" }); + this.sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerID", HeaderText = "Customer ID" }); + this.sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "Quantity", HeaderText = "Quantity" }); + this.sfDataGrid1.Columns.Add(new NumericUpDownExtColumn() { MappingName = "NumericUpDown", HeaderText = "NumericUpDown", Width = 150 }); + } + } + +} diff --git a/SfDataGridDemo/SfDatagridDemo/Form1.resx b/SfDataGridDemo/SfDatagridDemo/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SfDataGridDemo/SfDatagridDemo/OrderInfo.cs b/SfDataGridDemo/SfDatagridDemo/OrderInfo.cs new file mode 100644 index 0000000..3d71285 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/OrderInfo.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SfDatagridDemo +{ + public partial class OrderInfo : INotifyPropertyChanged + { + private int _OrderID; + + private string _CustomerID; + + private int _Quantity; + + private int _NumericUpDown; + + /// + /// Initializes a new instance of the class. + /// + public OrderInfo() + { + + } + + /// + /// Gets or sets the order ID. + /// + /// The order ID. + [Display(Name = "Order ID")] + public int OrderID + { + get + { + return this._OrderID; + } + set + { + this._OrderID = value; + this.OnPropertyChanged("OrderID"); + } + } + + /// + /// Gets or sets the customer ID. + /// + /// The customer ID. + [Display(Name = "Customer ID")] + public string CustomerID + { + get + { + return this._CustomerID; + } + set + { + this._CustomerID = value; + this.OnPropertyChanged("CustomerID"); + } + } + public int Quantity + { + get + { + return this._Quantity; + } + set + { + _Quantity = value; + OnPropertyChanged("Quantity"); + } + } + + public int NumericUpDown + { + get + { + return this._NumericUpDown; + } + set + { + _NumericUpDown = value; + OnPropertyChanged("NumericUpDown"); + } + } + public event PropertyChangedEventHandler PropertyChanged; + + private void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/SfDataGridDemo/SfDatagridDemo/Program.cs b/SfDataGridDemo/SfDatagridDemo/Program.cs new file mode 100644 index 0000000..f77e43c --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SfDatagridDemo +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/SfDataGridDemo/SfDatagridDemo/Properties/AssemblyInfo.cs b/SfDataGridDemo/SfDatagridDemo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b0bc95f --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SfDatagridDemo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SfDatagridDemo")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("99a85163-e55e-4123-8981-e23545b8580e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SfDataGridDemo/SfDatagridDemo/Properties/Resources.Designer.cs b/SfDataGridDemo/SfDatagridDemo/Properties/Resources.Designer.cs new file mode 100644 index 0000000..55c3fff --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SfDatagridDemo.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SfDatagridDemo.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/SfDataGridDemo/SfDatagridDemo/Properties/Resources.resx b/SfDataGridDemo/SfDatagridDemo/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SfDataGridDemo/SfDatagridDemo/Properties/Settings.Designer.cs b/SfDataGridDemo/SfDatagridDemo/Properties/Settings.Designer.cs new file mode 100644 index 0000000..960fe11 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SfDatagridDemo.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/SfDataGridDemo/SfDatagridDemo/Properties/Settings.settings b/SfDataGridDemo/SfDatagridDemo/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownCellRenderer.cs b/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownCellRenderer.cs new file mode 100644 index 0000000..6f4b4d7 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownCellRenderer.cs @@ -0,0 +1,54 @@ +using Syncfusion.Styles; +using Syncfusion.Windows.Forms; +using Syncfusion.Windows.Forms.Grid; +using Syncfusion.WinForms.DataGrid; +using Syncfusion.WinForms.DataGrid.Enums; +using Syncfusion.WinForms.DataGrid.Events; +using Syncfusion.WinForms.DataGrid.Helpers; +using Syncfusion.WinForms.DataGrid.Interactivity; +using Syncfusion.WinForms.DataGrid.Renderers; +using Syncfusion.WinForms.DataGrid.Styles; +using Syncfusion.WinForms.GridCommon.ScrollAxis; +using Syncfusion.WinForms.Input; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Printing; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Permissions; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using GridCellRendererBase = Syncfusion.WinForms.DataGrid.Renderers.GridCellRendererBase; + +namespace SfDatagridDemo.Renderer +{ + public class NumericUpDownCellRenderer : GridCellRendererBase + { + public NumericUpDownCellRenderer(SfDataGrid dataGrid) + { + DataGrid = dataGrid; + IsInEditing = false; + } + protected SfDataGrid DataGrid { get; set; } + + protected override void OnRender(Graphics graphics, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) + { + var NumericUpDownExtControl = new NumericUpDown(); + NumericUpDownExtControl.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; + NumericUpDownExtControl.Value = Convert.ToDecimal(cellValue); + NumericUpDownExtControl.Increment = new decimal(new int[] { 5, 0, 0, 0 }); + NumericUpDownExtControl.Minimum = new decimal(new int[] { 0, 0, 0, 0 }); + NumericUpDownExtControl.Maximum = new decimal(new int[] { 40, 0, 0, 0 }); + NumericUpDownExtControl.Font = new Font(NumericUpDownExtControl.Font.FontFamily, 14); + NumericUpDownExtControl.Text = cellValue ?? string.Empty; + NumericUpDownExtControl.Size = cellRect.Size; + NumericUpDownExtControl.Location = cellRect.Location; + DataGrid.GetTopLevelParentDataGrid().TableControl.Controls.Add(NumericUpDownExtControl); + } + } + + + +} diff --git a/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownExtColumn.cs b/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownExtColumn.cs new file mode 100644 index 0000000..78137a0 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownExtColumn.cs @@ -0,0 +1,19 @@ +using Syncfusion.WinForms.DataGrid; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SfDatagridDemo.Renderer +{ + public class NumericUpDownExtColumn:GridColumn + { + public NumericUpDownExtColumn() + { + SetCellType("NumericUpDown"); + } + + } +} diff --git a/SfDataGridDemo/SfDatagridDemo/SfDatagridDemo.csproj b/SfDataGridDemo/SfDatagridDemo/SfDatagridDemo.csproj new file mode 100644 index 0000000..2b4de68 --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/SfDatagridDemo.csproj @@ -0,0 +1,93 @@ + + + + + Debug + AnyCPU + {99A85163-E55E-4123-8981-E23545B8580E} + WinExe + SfDatagridDemo + SfDatagridDemo + v4.6.2 + 512 + true + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/SfDataGridDemo/SfDatagridDemo/ViewModel.cs b/SfDataGridDemo/SfDatagridDemo/ViewModel.cs new file mode 100644 index 0000000..d94282a --- /dev/null +++ b/SfDataGridDemo/SfDatagridDemo/ViewModel.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SfDatagridDemo +{ + public class ViewModel + { + public ViewModel() + { + OrdersListDetails = new OrderInfoRepository().GetListOrdersDetails(10); + } + + private List _ordersListDetails; + + /// + /// Gets or sets the orders details. + /// + /// The orders details. + public List OrdersListDetails + { + get { return _ordersListDetails; } + set { _ordersListDetails = value; } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool isdisposable) + { + if (this.OrdersListDetails != null) + { + this.OrdersListDetails.Clear(); + } + } + } + + public class OrderInfoRepository + { + int customerIdCount = 0; + + /// + /// Initializes a new instance of the class. + /// + public OrderInfoRepository() + { + } + + /// + /// Gets the orders details. + /// + /// The count. + /// + public List GetListOrdersDetails(int count) + { + List ordersDetails = new List(); + + for (int i = 10000; i < count + 10000; i++) + { + ordersDetails.Add(GetOrder(i)); + } + + return ordersDetails; + } + + Random r = new Random(1); + + + /// + /// Gets the order. + /// + /// The i. + /// + private OrderInfo GetOrder(int i) + { + + var order = new OrderInfo(); + order.OrderID = i; + order.CustomerID = GetCustomerID(i); + order.Quantity = r.Next(i % 100); + order.NumericUpDown = r.Next(i % 9); + return order; + } + + string GetCustomerID(int i) + { + if (i % 4 != 0 || i == 0) + { + return CustomerID[customerIdCount]; + } + else + { + if (i % 4 == 0) + customerIdCount++; + + if (customerIdCount > 9) + customerIdCount = 0; + + return CustomerID[customerIdCount]; + } + } + + + + + string[] CustomerID = new string[] + { + "ALFKI", + "FRANS", + "MEREP", + "FOLKO", + "SIMOB", + "WARTH", + "VAFFE", + "FURIB", + "SEVES", + "LINOD", + "RISCU", + "PICCO", + "BLONP", + "WELLI", + "FOLIG", + "SHIWL", + "ASDFI", + "YIWOL", + "SIEPZ", + "UIKOC", + "BNUTQ", + "FDKIO", + "UJIKW", + "QOLPX", + "WJXKO", + "SXEWD", + "ZXSOL", + "KKMJU", + "QMICP", + "SJWII", + "WDOPO", + "SAIOP", + "SSOLE", + "CUEMC", + "HWIMQ" + }; + } +}