Skip to content

Commit 01c5ed9

Browse files
Addressed the concerns.
1 parent c14025e commit 01c5ed9

File tree

6 files changed

+109
-65
lines changed

6 files changed

+109
-65
lines changed

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
1-
# How-to-implement-NumericUpDown-inside-SfDataGrid-using-Custom-Column-support.
2-
How to implement NumericUpDown inside SfDataGrid using Custom Column support.
1+
# How to implement NumericUpDown inside SfDataGrid using Custom Column support.
2+
3+
To achieve the requirement of implementing a NumericUpDown inside an SfDataGrid column, follow these steps:
4+
5+
**Step 1** : Create a custom column by overriding a new class derived from the GridColumn class.
6+
7+
```C#
8+
public class NumericUpDownExtColumn : GridColumn
9+
{
10+
public NumericUpDownExtColumn()
11+
{
12+
SetCellType("NumericUpDown");
13+
}
14+
15+
}
16+
```
17+
18+
**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.
19+
20+
**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.
21+
22+
You can add any other controls in the OnRender method by following this procedure based on your needs.
23+
24+
25+
```C#
26+
public class NumericUpDownCellRenderer : GridCellRendererBase
27+
{
28+
public NumericUpDownCellRenderer(SfDataGrid dataGrid)
29+
{
30+
DataGrid = dataGrid;
31+
IsInEditing = false;
32+
}
33+
protected SfDataGrid DataGrid { get; set; }
34+
35+
protected override void OnRender(Graphics graphics, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
36+
{
37+
var NumericUpDownExtControl = new NumericUpDown();
38+
NumericUpDownExtControl.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
39+
NumericUpDownExtControl.Value =Convert.ToDecimal(cellValue);
40+
NumericUpDownExtControl.Increment = new decimal(new int[] { 5, 0, 0, 0 });
41+
NumericUpDownExtControl.Minimum = new decimal(new int[] { 0, 0, 0, 0 });
42+
NumericUpDownExtControl.Maximum = new decimal(new int[] { 40, 0, 0, 0 });
43+
NumericUpDownExtControl.Font = new Font(NumericUpDownExtControl.Font.FontFamily, 14);
44+
NumericUpDownExtControl.Text = cellValue ?? string.Empty;
45+
NumericUpDownExtControl.Size = cellRect.Size;
46+
NumericUpDownExtControl.Location = cellRect.Location;
47+
DataGrid.GetTopLevelParentDataGrid().TableControl.Controls.Add(NumericUpDownExtControl);
48+
}
49+
}
50+
```
51+
52+
**Step 4** : Then you can add the previously created custom renderer to the SfDataGrid.CellRenderers collection.
53+
54+
55+
```C#
56+
public Form1()
57+
{
58+
InitializeComponent();
59+
this.sfDataGrid1.CellRenderers.Add("NumericUpDown", new NumericUpDownCellRenderer(sfDataGrid1));
60+
}
61+
```
62+
63+
**Step 5** : At last, finally, you can define the custom column in SfDataGrid.
64+
65+
66+
```C#
67+
public Form1()
68+
{
69+
InitializeComponent();
70+
this.sfDataGrid1.Columns.Add(new NumericUpDownExtColumn() { MappingName = "NumericUpDown", HeaderText = "NumericUpDown"});
71+
}
72+
```
73+
74+
By following the above code, the output image is as referenced below.
75+
76+
77+
![NumericUpDown_Image.png](https://support.syncfusion.com/kb/agent/attachment/article/15707/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjIwNzUxIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.yG2J64WnfEu5VJbuOnqjv_4Po3p_Ce82_OS9tDfBzuw)
78+
79+
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.

SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownCellRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public NumericUpDownCellRenderer(SfDataGrid dataGrid)
3636

3737
protected override void OnRender(Graphics graphics, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
3838
{
39-
var NumericUpDownExtControl = new NumericUpDownExtControl();
39+
var NumericUpDownExtControl = new NumericUpDown();
4040
NumericUpDownExtControl.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
4141
NumericUpDownExtControl.Value =Convert.ToDecimal(cellValue);
4242
NumericUpDownExtControl.Increment = new decimal(new int[] { 5, 0, 0, 0 });

SfDataGridDemo/SfDatagridDemo/Renderer/NumericUpDownExt.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

SfDataGridDemo/SfDatagridDemo/SfDatagridDemo.csproj

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,34 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="Syncfusion.Core.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
38-
<HintPath>..\packages\Syncfusion.Core.WinForms.25.1.38\lib\net40\Syncfusion.Core.WinForms.dll</HintPath>
37+
<Reference Include="Syncfusion.Core.WinForms, Version= *, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
3938
</Reference>
40-
<Reference Include="Syncfusion.Data.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Syncfusion.Data.WinForms.25.1.38\lib\net40\Syncfusion.Data.WinForms.dll</HintPath>
39+
<Reference Include="Syncfusion.Core.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Syncfusion.Core.WinForms.25.1.39\lib\net462\Syncfusion.Core.WinForms.dll</HintPath>
4241
</Reference>
43-
<Reference Include="Syncfusion.DataSource.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Syncfusion.DataSource.WinForms.25.1.38\lib\net40\Syncfusion.DataSource.WinForms.dll</HintPath>
42+
<Reference Include="Syncfusion.Data.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Syncfusion.Data.WinForms.25.1.39\lib\net462\Syncfusion.Data.WinForms.dll</HintPath>
4544
</Reference>
46-
<Reference Include="Syncfusion.GridCommon.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Syncfusion.GridCommon.WinForms.25.1.38\lib\net40\Syncfusion.GridCommon.WinForms.dll</HintPath>
45+
<Reference Include="Syncfusion.DataSource.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Syncfusion.DataSource.WinForms.25.1.39\lib\net462\Syncfusion.DataSource.WinForms.dll</HintPath>
4847
</Reference>
49-
<Reference Include="Syncfusion.Licensing, Version=25.1450.38.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Syncfusion.Licensing.25.1.38\lib\net45\Syncfusion.Licensing.dll</HintPath>
48+
<Reference Include="Syncfusion.GridCommon.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
49+
<HintPath>..\packages\Syncfusion.GridCommon.WinForms.25.1.39\lib\net462\Syncfusion.GridCommon.WinForms.dll</HintPath>
5150
</Reference>
52-
<Reference Include="Syncfusion.SfDataGrid.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
53-
<HintPath>..\packages\Syncfusion.SfDataGrid.WinForms.25.1.38\lib\net40\Syncfusion.SfDataGrid.WinForms.dll</HintPath>
51+
<Reference Include="Syncfusion.Licensing, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Syncfusion.Licensing.25.1.39\lib\net462\Syncfusion.Licensing.dll</HintPath>
5453
</Reference>
55-
<Reference Include="Syncfusion.SfInput.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
56-
<HintPath>..\packages\Syncfusion.SfInput.WinForms.25.1.38\lib\net40\Syncfusion.SfInput.WinForms.dll</HintPath>
54+
<Reference Include="Syncfusion.SfDataGrid.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
55+
<HintPath>..\packages\Syncfusion.SfDataGrid.WinForms.25.1.39\lib\net462\Syncfusion.SfDataGrid.WinForms.dll</HintPath>
5756
</Reference>
58-
<Reference Include="Syncfusion.SfListView.WinForms, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
59-
<HintPath>..\packages\Syncfusion.SfListView.WinForms.25.1.38\lib\net40\Syncfusion.SfListView.WinForms.dll</HintPath>
57+
<Reference Include="Syncfusion.SfInput.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
58+
<HintPath>..\packages\Syncfusion.SfInput.WinForms.25.1.39\lib\net462\Syncfusion.SfInput.WinForms.dll</HintPath>
6059
</Reference>
61-
<Reference Include="Syncfusion.Shared.Base, Version=25.1400.38.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
62-
<HintPath>..\packages\Syncfusion.Shared.Base.25.1.38\lib\net40\Syncfusion.Shared.Base.dll</HintPath>
60+
<Reference Include="Syncfusion.SfListView.WinForms, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
61+
<HintPath>..\packages\Syncfusion.SfListView.WinForms.25.1.39\lib\net462\Syncfusion.SfListView.WinForms.dll</HintPath>
62+
</Reference>
63+
<Reference Include="Syncfusion.Shared.Base, Version=25.1462.39.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
64+
<HintPath>..\packages\Syncfusion.Shared.Base.25.1.39\lib\net462\Syncfusion.Shared.Base.dll</HintPath>
6365
</Reference>
6466
<Reference Include="System" />
6567
<Reference Include="System.ComponentModel.DataAnnotations" />
@@ -86,9 +88,6 @@
8688
<Compile Include="Program.cs" />
8789
<Compile Include="Properties\AssemblyInfo.cs" />
8890
<Compile Include="Renderer\NumericUpDownCellRenderer.cs" />
89-
<Compile Include="Renderer\NumericUpDownExt.cs">
90-
<SubType>Component</SubType>
91-
</Compile>
9291
<Compile Include="Renderer\NumericUpDownExtColumn.cs" />
9392
<Compile Include="ViewModel.cs" />
9493
<EmbeddedResource Include="Form1.resx">

SfDataGridDemo/SfDatagridDemo/SfDatagridDemo.csproj.user

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Syncfusion.Core.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
4-
<package id="Syncfusion.Data.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
5-
<package id="Syncfusion.DataSource.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
6-
<package id="Syncfusion.GridCommon.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
7-
<package id="Syncfusion.Licensing" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
8-
<package id="Syncfusion.SfDataGrid.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
9-
<package id="Syncfusion.SfInput.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
10-
<package id="Syncfusion.SfListView.WinForms" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
11-
<package id="Syncfusion.Shared.Base" version="25.1.38" targetFramework="net46" requireReinstallation="true" />
3+
<package id="Syncfusion.Core.WinForms" version="25.1.39" targetFramework="net462" />
4+
<package id="Syncfusion.Data.WinForms" version="25.1.39" targetFramework="net462" />
5+
<package id="Syncfusion.DataSource.WinForms" version="25.1.39" targetFramework="net462" />
6+
<package id="Syncfusion.GridCommon.WinForms" version="25.1.39" targetFramework="net462" />
7+
<package id="Syncfusion.Licensing" version="25.1.39" targetFramework="net462" />
8+
<package id="Syncfusion.SfDataGrid.WinForms" version="25.1.39" targetFramework="net462" />
9+
<package id="Syncfusion.SfInput.WinForms" version="25.1.39" targetFramework="net462" />
10+
<package id="Syncfusion.SfListView.WinForms" version="25.1.39" targetFramework="net462" />
11+
<package id="Syncfusion.Shared.Base" version="25.1.39" targetFramework="net462" />
1212
</packages>

0 commit comments

Comments
 (0)