This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
Window1.xaml.cs
50 lines (45 loc) · 2.01 KB
/
Window1.xaml.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
using System;
using System.Collections.Generic;
using System.Windows;
using DevExpress.Xpf.Grid;
using DXGrid_RowSelection.nwindDataSetTableAdapters;
namespace DXGrid_RowSelection {
public partial class Window1 : Window {
private List<bool> unboundItemsSource = new List<bool>();
public Window1() {
InitializeComponent();
nwindDataSet.ProductsDataTable gridData = new ProductsTableAdapter().GetData();
FillUnboundItemsSource(gridData.Rows.Count);
grid.ItemsSource = gridData;
}
private void FillUnboundItemsSource(int capacity) {
for (int i = 0; i < capacity; i++)
unboundItemsSource.Add(false);
}
private void grid_CustomSummary(object sender, DevExpress.Data.CustomSummaryEventArgs e) {
if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start)
e.TotalValue = 0;
if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate)
if ((bool)e.GetValue("Selected"))
e.TotalValue = Convert.ToDecimal(e.TotalValue) +
Convert.ToDecimal(e.GetValue("UnitPrice"));
}
private void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
if (e.Column.FieldName == "Selected") {
if (e.IsGetData)
e.Value = unboundItemsSource[e.ListSourceRowIndex];
if (e.IsSetData)
unboundItemsSource[e.ListSourceRowIndex] = (bool)e.Value;
}
}
private void TableView_MouseDoubleClick(object sender,
System.Windows.Input.MouseButtonEventArgs e) {
int rowHandle = grid.View.GetRowHandleByMouseEventArgs(e);
if (grid.IsValidRowHandle(rowHandle)) {
grid.SetCellValue(rowHandle, "Selected",
!(bool)grid.GetCellValue(rowHandle, "Selected"));
grid.RefreshData();
}
}
}
}