Skip to content

Commit c3abf1f

Browse files
Merge pull request #1 from FarjanaParveen/master
How to create the single group for null and empty value in Windows Forms DataGrid(SfDataGrid)?
2 parents a78ca45 + 9e07807 commit c3abf1f

File tree

12 files changed

+809
-2
lines changed

12 files changed

+809
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
# how-to-create-the-single-group-for-null-and-empty-value-in-windows-forms-datagrid-sfdatagrid-
2-
How to create the single group for null and empty value in Windows Forms DataGrid(SfDataGrid)
1+
# How to create the single group for null and empty value in Windows Forms DataGrid(SfDataGrid)?
2+
3+
## About the sample
4+
5+
This example illustrates how to create the single group for null and empty value in Windows Forms DataGrid(SfDataGrid)
6+
7+
By default, empty and null values are created the separate groups in SfDataGrid. You can able to create the single group for empty and null value by using KeySelector in GroupColumnDescriptions.
8+
9+
```C#
10+
this.sfDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
11+
{
12+
ColumnName = "Country",
13+
KeySelector = (string ColumnName, object o) =>
14+
{
15+
var item = (o as OrderInfo).Country;
16+
if (item == null || item == "")
17+
{
18+
return "";
19+
}
20+
21+
return item;
22+
}
23+
});
24+
```
25+
26+
## Requirements to run the demo
27+
Visual Studio 2015 and above versions
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3839D384-FF5F-4FB9-B1D1-7918E512B434}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>AddNewRow</RootNamespace>
11+
<AssemblyName>AddNewRow</AssemblyName>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="DemoCommon" />
37+
<Reference Include="Syncfusion.Core.WinForms" />
38+
<Reference Include="Syncfusion.Data.WinForms" />
39+
<Reference Include="Syncfusion.GridCommon.WinForms" />
40+
<Reference Include="Syncfusion.SfDataGrid.WinForms" />
41+
<Reference Include="Syncfusion.SfInput.WinForms" />
42+
<Reference Include="Syncfusion.SfListView.WinForms" />
43+
<Reference Include="Syncfusion.Shared.Base" />
44+
<Reference Include="Syncfusion.DataSource.WinForms" />
45+
<Reference Include="System" />
46+
<Reference Include="System.ComponentModel.DataAnnotations" />
47+
<Reference Include="System.Core" />
48+
<Reference Include="System.Data.Linq" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="Microsoft.CSharp" />
52+
<Reference Include="System.Data" />
53+
<Reference Include="System.Deployment" />
54+
<Reference Include="System.Drawing" />
55+
<Reference Include="System.Windows.Forms" />
56+
<Reference Include="System.Xml" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="Form1.cs">
60+
<SubType>Form</SubType>
61+
</Compile>
62+
<Compile Include="Form1.Designer.cs">
63+
<DependentUpon>Form1.cs</DependentUpon>
64+
</Compile>
65+
<Compile Include="Program.cs" />
66+
<Compile Include="Properties\AssemblyInfo.cs" />
67+
<EmbeddedResource Include="Form1.resx">
68+
<DependentUpon>Form1.cs</DependentUpon>
69+
</EmbeddedResource>
70+
<EmbeddedResource Include="Properties\Resources.resx">
71+
<Generator>ResXFileCodeGenerator</Generator>
72+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
73+
<SubType>Designer</SubType>
74+
</EmbeddedResource>
75+
<Compile Include="Properties\Resources.Designer.cs">
76+
<AutoGen>True</AutoGen>
77+
<DependentUpon>Resources.resx</DependentUpon>
78+
<DesignTime>True</DesignTime>
79+
</Compile>
80+
<None Include="Properties\Settings.settings">
81+
<Generator>SettingsSingleFileGenerator</Generator>
82+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
83+
</None>
84+
<Compile Include="Properties\Settings.Designer.cs">
85+
<AutoGen>True</AutoGen>
86+
<DependentUpon>Settings.settings</DependentUpon>
87+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
88+
</Compile>
89+
</ItemGroup>
90+
<ItemGroup>
91+
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
92+
</ItemGroup>
93+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
94+
<ItemGroup>
95+
<Reference Include="Syncfusion.Licensing" />
96+
</ItemGroup>
97+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
98+
Other similar extension points exist, see Microsoft.Common.targets.
99+
<Target Name="BeforeBuild">
100+
</Target>
101+
<Target Name="AfterBuild">
102+
</Target>
103+
-->
104+
</Project>

SfDataGridDemo/AddNewRow_2015.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddNewRow_2015", "AddNewRow_2015.csproj", "{3839D384-FF5F-4FB9-B1D1-7918E512B434}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{3839D384-FF5F-4FB9-B1D1-7918E512B434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{3839D384-FF5F-4FB9-B1D1-7918E512B434}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{3839D384-FF5F-4FB9-B1D1-7918E512B434}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{3839D384-FF5F-4FB9-B1D1-7918E512B434}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

SfDataGridDemo/Form1.Designer.cs

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SfDataGridDemo/Form1.cs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using DemoCommon.Grid;
2+
using Syncfusion.Data;
3+
using Syncfusion.WinForms.DataGrid;
4+
using Syncfusion.WinForms.DataGrid.Enums;
5+
using System;
6+
using System.Collections.ObjectModel;
7+
using System.ComponentModel;
8+
using System.Windows.Forms;
9+
10+
namespace AddNewRow
11+
{
12+
/// <summary>
13+
/// Summary description for Form1.
14+
/// </summary>
15+
public partial class Form1 : Form
16+
{
17+
#region Constructor
18+
19+
OrderInfoCollection orderInfoCollection = new OrderInfoCollection();
20+
21+
public Form1()
22+
{
23+
InitializeComponent();
24+
sfDataGrid.DataSource = orderInfoCollection.Orders;
25+
sfDataGrid.ShowGroupDropArea = true;
26+
27+
this.sfDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
28+
{
29+
ColumnName = "Country",
30+
KeySelector = (string ColumnName, object o) =>
31+
{
32+
var item = (o as OrderInfo).Country;
33+
if (item == null || item == "")
34+
{
35+
return "";
36+
}
37+
38+
return item; ;
39+
}
40+
});
41+
}
42+
}
43+
44+
#endregion
45+
}
46+
47+
public class OrderInfo : INotifyPropertyChanged
48+
{
49+
int orderID;
50+
string customerId;
51+
string country;
52+
string customerName;
53+
string shippingCity;
54+
55+
public event PropertyChangedEventHandler PropertyChanged;
56+
57+
public int OrderID
58+
{
59+
get { return orderID; }
60+
set
61+
{
62+
orderID = value;
63+
RaisePropertyChanged("OrderID");
64+
}
65+
}
66+
public string CustomerID
67+
{
68+
get { return customerId; }
69+
set
70+
{
71+
customerId = value;
72+
RaisePropertyChanged("CustomerID");
73+
}
74+
}
75+
public string CustomerName
76+
{
77+
get { return customerName; }
78+
set
79+
{
80+
customerName = value;
81+
RaisePropertyChanged("CustomerName");
82+
}
83+
}
84+
public string Country
85+
{
86+
get { return country; }
87+
set
88+
{
89+
country = value;
90+
RaisePropertyChanged("Country");
91+
}
92+
}
93+
public string ShipCity
94+
{
95+
get { return shippingCity; }
96+
set
97+
{
98+
shippingCity = value;
99+
RaisePropertyChanged("ShipCity");
100+
}
101+
}
102+
public OrderInfo(int orderId, string customerName, string country, string customerId, string shipCity)
103+
{
104+
this.OrderID = orderId;
105+
this.CustomerName = customerName;
106+
this.Country = country;
107+
this.CustomerID = customerId;
108+
this.ShipCity = shipCity;
109+
}
110+
111+
/// <summary>
112+
/// Occurs when any property value changed.
113+
/// </summary>
114+
/// <param name="propertyName">The name of the property which was changed.</param>
115+
private void RaisePropertyChanged(string propertyName)
116+
{
117+
if (PropertyChanged != null)
118+
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
119+
}
120+
}
121+
122+
public class OrderInfoCollection
123+
{
124+
public ObservableCollection<OrderInfo> _orders;
125+
public ObservableCollection<OrderInfo> Orders
126+
{
127+
get { return _orders; }
128+
set { _orders = value; }
129+
}
130+
public OrderInfoCollection()
131+
{
132+
_orders = new ObservableCollection<OrderInfo>();
133+
this.GenerateOrders();
134+
}
135+
private void GenerateOrders()
136+
{
137+
_orders.Add(new OrderInfo(1001, "Maria Anders", null, "ALFKI", "Berlin"));
138+
_orders.Add(new OrderInfo(1002, "Ana Trujilo", null, "ANATR", "Mexico D.F."));
139+
_orders.Add(new OrderInfo(1003, "Antonio Moreno", null, "ANTON", "Mexico D.F."));
140+
_orders.Add(new OrderInfo(1004, "Thomas Hardy", "UK", "AROUT", "London"));
141+
_orders.Add(new OrderInfo(1005, "Christina Berglund", string.Empty, "BERGS", "Lula"));
142+
_orders.Add(new OrderInfo(1006, "Hanna Moos", "Germany", "BLAUS", "Mannheim"));
143+
_orders.Add(new OrderInfo(1007, "Frederique Citeaux", string.Empty, "BLONP", "Strasbourg"));
144+
_orders.Add(new OrderInfo(1008, "Martin Sommer", "Spain", "BOLID", "Madrid"));
145+
_orders.Add(new OrderInfo(1009, "Laurence Lebihan", "France", "BONAP", "Marseille"));
146+
_orders.Add(new OrderInfo(1010, "Elizabeth Lincoln", "Canada", "BOTTM", "Tsawassen"));
147+
_orders.Add(new OrderInfo(1011, "Maria Anders", null, "ALFKI", "Berlin"));
148+
_orders.Add(new OrderInfo(1012, "Ana Trujilo", "Mexico", "ANATR", "Mexico D.F."));
149+
_orders.Add(new OrderInfo(1013, "Antonio Moreno", "Mexico", "ANTON", "Mexico D.F."));
150+
_orders.Add(new OrderInfo(1014, "Thomas Hardy", string.Empty, "AROUT", "London"));
151+
_orders.Add(new OrderInfo(1015, "Christina Berglund", "Sweden", "BERGS", "Lula"));
152+
_orders.Add(new OrderInfo(1016, "Hanna Moos", string.Empty, "BLAUS", "Mannheim"));
153+
_orders.Add(new OrderInfo(1017, "Frederique Citeaux", "France", "BLONP", "Strasbourg"));
154+
_orders.Add(new OrderInfo(1018, "Martin Sommer", string.Empty, "BOLID", "Madrid"));
155+
_orders.Add(new OrderInfo(1019, "Laurence Lebihan", "France", "BONAP", "Marseille"));
156+
_orders.Add(new OrderInfo(1020, "Elizabeth Lincoln", null, "BOTTM", "Tsawassen"));
157+
}
158+
}

0 commit comments

Comments
 (0)