-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
67 lines (61 loc) · 2.56 KB
/
Form1.cs
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
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Data;
using System.Windows.Forms;
namespace Q273845
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
productsBindingSource.DataSource = GetProductsDataTable();
}
DataTable GetProductsDataTable()
{
DataTable table = new DataTable();
table.TableName = "Products";
table.Columns.Add(new DataColumn("ProductName", typeof(string)));
table.Columns.Add(new DataColumn("UnitsInStock", typeof(int)));
table.Columns.Add(new DataColumn("UnitPrice", typeof(double)));
table.Columns.Add(new DataColumn("Category", typeof(string)));
Random random = new Random();
for(int i = 0; i < 20; i++)
{
int index = i + 1;
table.Rows.Add("Product " + index, random.Next(1, 20), Math.Round(random.NextDouble() * 1000, 3), "Category " + i % 7);
}
return table;
}
private void gridView1_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
if(e.Column == colPrice)
e.Info.DisplayText = (Convert.ToDecimal(colUnitPrice.SummaryItem.SummaryValue) *
Convert.ToDecimal(colUnitsInStock.SummaryItem.SummaryValue)).ToString();
}
private void gridView1_CustomDrawRowFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
if(e.Column == colPrice)
{
GridView view = (GridView)sender;
e.Info.DisplayText = (Convert.ToDecimal(view.GetGroupSummaryValue(e.RowHandle,
(GridGroupSummaryItem)view.GroupSummary["UnitPrice"])) *
Convert.ToDecimal(view.GetGroupSummaryValue(e.RowHandle,
(GridGroupSummaryItem)view.GroupSummary["UnitsInStock"]))).ToString();
}
}
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
GridView view = (GridView)sender;
if(e.Column == colPrice)
if(e.IsGetData)
e.Value = Convert.ToDecimal(view.GetListSourceRowCellValue(e.ListSourceRowIndex, colUnitPrice)) *
Convert.ToInt32(view.GetListSourceRowCellValue(e.ListSourceRowIndex, colUnitsInStock));
}
}
}