Skip to content

Commit 7fe8722

Browse files
authored
ModifiedSample
ModifiedSample
1 parent 2d4dc97 commit 7fe8722

File tree

4 files changed

+30
-62
lines changed

4 files changed

+30
-62
lines changed

MergedCell.png

-1.21 KB
Loading

SfDataGridDemo/SfDataGridDemo/MainWindow.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public sealed partial class MainWindow : Window
2929
public MainWindow()
3030
{
3131
this.InitializeComponent();
32-
this.sfDataGrid.ItemsSourceChanged += SfDataGrid_ItemsSourceChanged;
33-
this.sfDataGrid.QueryCoveredRange += SfDataGrid_QueryCoveredRange;
32+
this.sfDataGrid.ItemsSourceChanged += OnItemsSourceChanged;
33+
this.sfDataGrid.QueryCoveredRange += OnQueryCoveredRange;
3434
}
3535

3636

@@ -43,7 +43,7 @@ public MainWindow()
4343
/// <summary>
4444
/// ItemsSourceChanged event handler.
4545
/// </summary>
46-
private void SfDataGrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)
46+
private void OnItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)
4747
{
4848
if (sfDataGrid.View != null)
4949
reflector = sfDataGrid.View.GetPropertyAccessProvider();
@@ -54,12 +54,12 @@ private void SfDataGrid_ItemsSourceChanged(object sender, GridItemsSourceChanged
5454
/// <summary>
5555
/// QueryCoveredRange event handler
5656
/// </summary>
57-
private void SfDataGrid_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
57+
private void OnQueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
5858
{
5959
CoveredCellInfo range = null;
6060

6161
////here apply merge the cell based on Columns
62-
if (e.GridColumn.MappingName == "Product" || e.GridColumn.MappingName == "Country" || e.GridColumn.MappingName == "Discount")
62+
if (e.GridColumn.MappingName == "Product" || e.GridColumn.MappingName == "Country" )
6363
range = GetRange(e.GridColumn, e.RowColumnIndex.RowIndex, e.RowColumnIndex.ColumnIndex, e.Record);
6464

6565
if (range == null)
@@ -89,7 +89,7 @@ private CoveredCellInfo GetRange(GridColumn column, int rowIndex, int columnInde
8989
var range = new CoveredCellInfo(columnIndex, columnIndex, rowIndex, rowIndex);
9090
object data = reflector.GetFormattedValue(rowData, column.MappingName);
9191

92-
//here get the Product value for checikng other cell value
92+
//here get the Product value for checking other cell value
9393
string productData = (rowData as ProductSalesDetails).Product;
9494

9595
GridColumn leftColumn = null;
@@ -211,7 +211,7 @@ private CoveredCellInfo GetRange(GridColumn column, int rowIndex, int columnInde
211211
break;
212212
var compareData = reflector.GetFormattedValue((nextData as RecordEntry).Data, column.MappingName);
213213

214-
//get the next row data value of RigID
214+
//get the next row data value of Product
215215
string productNextData = ((nextData as RecordEntry).Data as ProductSalesDetails).Product;
216216

217217
if (compareData == null)

SfDataGridDemo/SfDataGridDemo/Model/ProductSalesDetails.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,16 @@ private void RaisePropertyChanged(string propertyName)
149149
if (PropertyChanged != null)
150150
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
151151
}
152+
153+
public ProductSalesDetails(string product, string country, string state,int quantity,double discount,double amount)
154+
{
155+
this.Product = product;
156+
this.Country = country;
157+
this.State = state;
158+
this.Quantity = quantity;
159+
this.Discount = discount;
160+
this.Amount = amount;
161+
162+
}
152163
}
153164
}

SfDataGridDemo/SfDataGridDemo/ViewModel/ProductSalesDetailsCollection.cs

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -54,62 +54,19 @@ public ObservableCollection<ProductSalesDetails> ProductInfo
5454
/// <returns></returns>
5555
public ObservableCollection<ProductSalesDetails> GetSalesInfo()
5656
{
57-
/// Geography
58-
string[] countries = new string[] { "Australia", "Canada", "France", "Germany", "United States" };
59-
string[] ausStates = new string[] { "New South Wales", "Queensland", "South Australia", "Tasmania", "Victoria" };
60-
string[] canadaStates = new string[] { "Alberta", "British Columbia", "Brunswick", "Manitoba", "Ontario", "Quebec" };
61-
string[] franceStates = new string[] { "Charente-Maritime", "Essonne", "Garonne (Haute)", "Gers", };
62-
string[] germanyStates = new string[] { "Bayern", "Brandenburg", "Hamburg", "Hessen", "Nordrhein-Westfalen", "Saarland" };
57+
_productInfo = new ObservableCollection<ProductSalesDetails>();
58+
_productInfo.Add(new ProductSalesDetails("Bike", "Germany", "Bayern", 9, 12, 25000));
59+
_productInfo.Add(new ProductSalesDetails("Bike", "Germany", "Brandenburg", 8, 14, 36000));
60+
_productInfo.Add(new ProductSalesDetails("Bike", "Germany", "Hamburg", 5, 8, 40040));
61+
_productInfo.Add(new ProductSalesDetails("Car", "Germany", "Hessen", 3, 10, 10700));
62+
_productInfo.Add(new ProductSalesDetails("Car", "Germany", "Bayern", 8, 13, 20300));
63+
_productInfo.Add(new ProductSalesDetails("Truck", "Australia", "Queensland", 5, 7, 50700));
64+
_productInfo.Add(new ProductSalesDetails("Van", "Canada", "Alberta", 6, 8, 80100));
65+
_productInfo.Add(new ProductSalesDetails("BiCycle", "Canada", "Brunswick", 2, 6, 35000));
66+
_productInfo.Add(new ProductSalesDetails("Car", "France", "Essonne", 4, 8, 20030));
67+
_productInfo.Add(new ProductSalesDetails("Bike", "United States", "New York", 3, 7, 54000));
6368

64-
string[] ussStates = new string[] { "New York", "North Carolina", "Alabama", "California", "Colorado", "New Mexico", "South Carolina" };
65-
66-
/// Products
67-
string[] products = new string[] { "Bike", "Car", "Truck", "Van", "BiCycle" };
68-
Random r = new Random(0);
69-
70-
int numberOfRecords = 10;
71-
ObservableCollection<ProductSalesDetails> listOfProductSales = new ObservableCollection<ProductSalesDetails>();
72-
for (int i = 0; i < numberOfRecords; i++)
73-
{
74-
ProductSalesDetails sales = new ProductSalesDetails();
75-
sales.Country = countries[r.Next(1, countries.GetLength(0))];
76-
sales.Quantity = r.Next(1, 12);
77-
sales.Discount = r.Next(1, 15);
78-
sales.Amount = (30000 * sales.Quantity);
79-
sales.Product = products[r.Next(r.Next(products.GetLength(0) + 1))];
80-
switch (sales.Country)
81-
{
82-
case "Australia":
83-
{
84-
sales.State = ausStates[r.Next(ausStates.GetLength(0))];
85-
break;
86-
}
87-
case "Canada":
88-
{
89-
sales.State = canadaStates[r.Next(canadaStates.GetLength(0))];
90-
break;
91-
}
92-
case "France":
93-
{
94-
sales.State = franceStates[r.Next(franceStates.GetLength(0))];
95-
break;
96-
}
97-
case "Germany":
98-
{
99-
sales.State = germanyStates[r.Next(germanyStates.GetLength(0))];
100-
break;
101-
}
102-
case "United States":
103-
{
104-
sales.State = ussStates[r.Next(ussStates.GetLength(0))];
105-
break;
106-
}
107-
}
108-
109-
listOfProductSales.Add(sales);
110-
}
111-
112-
return listOfProductSales;
69+
return _productInfo;
11370
}
11471
}
11572
}

0 commit comments

Comments
 (0)