此案例是关于Dev GridControl 合chartControl 控件的显示数据,
GridControl 控件:
1.绑定IList<T> 对象,
2.实现全选,
- //点击全选按钮取得方法
- private void checkEdit1_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- listP = gridControl1.DataSource as IList<Perf_cell_g>;
- for (int i = 0; i < listP.Count; i++)
- {
- Perf_cell_g p = listP[i] as Perf_cell_g;
- p.CHECK = checkEdit1.Checked;
- }
- gridControl1.RefreshDataSource();
- }
- catch (Exception)
- {
- }
- }
3.删除选择的多行,
- /// <summary>
- /// 删除选中行的数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void simpleButton2_Click(object sender, EventArgs e)
- {
- List<string> selectedRows = new List<string>();
- listP = gridControl1.DataSource as IList<Perf_cell_g>;
- for (int i = 0; i < listP.Count; i++)
- {
- Perf_cell_g p = listP[i] as Perf_cell_g;
- if (p.CHECK.ToString().ToLower() == "true")
- {
- selectedRows.Add(p.CHECK.ToString());
- }
- }
- if (DialogResult.OK == MessageBox.Show("确认删除此模板?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
- {
- MessageBox.Show(string.Format("选中了{0}个需要删除的数据", selectedRows.Count));
- }
- //删除选中的行
- }
4.在GridControl 最下行显示某列所有数据计算总和、某列下行显示总记录数,
- //设置属性
- this.gridColumn2.SummaryItem.DisplayFormat = "总记录数={0}";
- this.gridColumn2.SummaryItem.FieldName = "CHINA_NAME";
- this.gridColumn2.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
5.某列中对于数据>3300 该列特殊颜色显示,
- 方法一(写方法):
- /// <summary>
- /// 行单元格的样式 对于Ci列如果改列值大于3300 高亮显示该列
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
- {
- try
- {
- if (e.Column.FieldName != "Ci")
- return;
- string ciV = gridView1.GetListSourceRowCellValue(e.RowHandle, e.Column.FieldName).ToString(); //获取ci 列的值
- if (ciV.Trim() != "")
- {
- if (Convert.ToInt32(ciV) > 3300)
- {
- DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appType1);
- }
- }
- }
- catch { }
- }
- 方法二(属性设置GridView1 属性中添加):
- styleFormatCondition1.Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
- styleFormatCondition1.Appearance.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
- styleFormatCondition1.Appearance.ForeColor = System.Drawing.Color.Black;
- styleFormatCondition1.Appearance.GradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
- styleFormatCondition1.Appearance.Options.UseBackColor = true;
- styleFormatCondition1.Appearance.Options.UseForeColor = true;
- styleFormatCondition1.Column = this.gridColumn4;
- styleFormatCondition1.Condition = DevExpress.XtraGrid.FormatConditionEnum.GreaterOrEqual;
- styleFormatCondition1.Value1 = "3300";
- this.gridView1.FormatConditions.AddRange(new DevExpress.XtraGrid.StyleFormatCondition[] {
- styleFormatCondition1});
6.隐藏GridControl 表最上行的英文字符
7.设置GridControl 中除了check 列之外的列不能编辑
chartControl 控件:
1.点击GridControl 该行某列下表显示该列的线性图形(chartControl)
2.根据GridControl 选择行某列的值,图的标题相应改变为该列的值
SplitterControl 用于分割两个控件 // // splitterControl1 // this.splitterControl1.Dock = System.Windows.Forms.DockStyle.Bottom; this.splitterControl1.Location = new System.Drawing.Point(0, 336); this.splitterControl1.Name = "splitterControl1"; this.splitterControl1.Size = new System.Drawing.Size(1028, 6); this.splitterControl1.TabIndex = 1; this.splitterControl1.TabStop = false; 效果图片: