using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
public partial class Form1 : Form
gridView1.GroupPanelText = "深圳精品4S旗舰店订单管理:";
gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Top;
gridView1.OptionsBehavior.Editable = true;
//gridView1选中行后按快捷键 “Ctrl+Del” 删除
gridControl1.ProcessGridKey += (s, e) =>
if (e.KeyCode == Keys.Delete && e.Modifiers == Keys.Control)
if (XtraMessageBox.Show("是否删除选中行?", "删除行对话框", MessageBoxButtons.YesNo) !=
GridControl grid = s as GridControl;
GridView view = grid.FocusedView as GridView;
view.DeleteSelectedRows();
/// 字段属性设置并验证字段属性数据的正确性,属性变更后向客户端发出属性值已更改的通知。
public class Record : INotifyPropertyChanged
if (string.IsNullOrEmpty(value))
[DataType(DataType.Currency)]
public Nullable<decimal> Value
public DateTime RequiredDate
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
public static string[] brands = new string[] { "奔驰", "宝马", "奥迪", "大众",
"马自达", "雷克萨斯", "红旗" ,"路虎","丰田","本田","现代"};
public static BindingList<Record> GetData(int count)
BindingList<Record> records = new BindingList<Record>();
Random rnd = new Random();
for (int i = 0; i < count; i++)
Brand = brands[i % brands.Length],
RequiredDate = DateTime.Today.AddDays(n + 30),
Value = i % 2 == 0 ? (i + 1) * 123456 : i * 12345,
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_Output_Click(object sender, EventArgs e)
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Title = "导出Excel";
fileDialog.Filter = "Excel文件(*.xls)|*.xls";
DialogResult dialogResult = fileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
DevExpress.XtraPrinting.XlsExportOptions options = new
DevExpress.XtraPrinting.XlsExportOptions();
gridControl1.ExportToXls(fileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
private void Form1_Load(object sender, EventArgs e)
//dataGrid自动在数据源中找到公共字段并创建列。
gridControl1.DataSource = DataHelper.GetData(10);
//创建一个ComboBox编辑器,在“品牌”列中显示可用的品牌。
RepositoryItemComboBox riComboBox = new RepositoryItemComboBox();
riComboBox.Items.AddRange(DataHelper.brands);
gridControl1.RepositoryItems.Add(riComboBox);
gridView1.Columns["Brand"].ColumnEdit = riComboBox;
GridColumn colID = gridView1.Columns["ID"];
colID.AppearanceCell.BackColor2 = Color.DarkGreen;
colID.AppearanceCell.BackColor = Color.LightGreen;
colID.AppearanceCell.ForeColor = Color.White;
GridColumn colCompanyName = gridView1.Columns["Brand"];
colCompanyName.AppearanceCell.BackColor = Color.DarkKhaki;
colCompanyName.AppearanceCell.ForeColor = Color.Black;
GridColumn colRequiredDate = gridView1.Columns["RequiredDate"];
colRequiredDate.AppearanceCell.ForeColor = Color.Red;
private void Button1_Click(object sender, EventArgs e)
System.Diagnostics.Process.Start("https://www.daboke.com");
private void Button2_Click(object sender, EventArgs e)
System.Diagnostics.Process.Start("https://www.daboke.com/devexpress/gridcontrol.html");
private void Button3_Click(object sender, EventArgs e)
//欢迎访问我的B站频道-编程自修室,观看更多C#编程实战视频!
System.Diagnostics.Process.Start("https://space.bilibili.com/580719958");