保留选中数据,其他数据删除,不操作数据库

private void butnoremove_Click(object sender, EventArgs e)
{
int iSelectRowCount = gridView1.SelectedRowsCount;
if (iSelectRowCount > )
{
if (MessageBox.Show("你确定只保留选中的记录吗?", "提示", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, , false) == DialogResult.Yes)
{ for (int i = ; i < gridView1.DataRowCount; i++)
{
int handle = gridView1.GetRowHandle(i);
if (!gridView1.IsRowSelected(handle))
{
gridView1.DeleteRow(handle);
i = i - ;
}
}
}
}
else
{
MessageBox.Show("请先选中要保留的记录", "提示");
}
}

行样式和格样式的设置

private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
//GridView View = sender as GridView;
//if (e.RowHandle >= 0)
//{
// string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["clores"]);
// int i = Convert.ToInt32(category);
// if (i % 2 == 0)
// {
// e.Appearance.BackColor = Color.Salmon;
// e.Appearance.BackColor2 = Color.SeaShell;
// }
//}
}
private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "content")
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["content"]);
}
if (e.Column.FieldName == "volumeWeight" || e.Column.FieldName == "weightes")
{
e.Appearance.ForeColor = Color.YellowGreen;
}
if (e.Column.FieldName == "fweight" || e.Column.FieldName == "cfweight")
e.Appearance.ForeColor = Color.Coral;
}
}

导出excel

try
{
string path = "";
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Filter = "Excel文件|*.xls";
if (sfd.ShowDialog() == DialogResult.Cancel)
{
return;
}
path += sfd.FileName;
}
dvginfo.ExportToXls(path);
}
catch (Exception ex)
{
MessageBox.Show("请先关闭要替换的文件", "提示");
}

动态创建gridview,导出Excel数据

GridControl CreateGrid(List<marketinformation> pagemodel)
{
GridControl grid = new GridControl(); ;
GridView view = new GridView();
grid.ViewCollection.Add(view);
grid.MainView = view;
view.GridControl = grid; foreach (GridColumn column in gridView2.Columns)
{
DevExpress.XtraGrid.Columns.GridColumn gridColumnNumber = view.Columns.AddVisible
(column.FieldName.ToString());
gridColumnNumber.Caption = column.Caption.ToString();
gridColumnNumber.FieldName = column.FieldName.ToString();
}
grid.DataSource = pagemodel;
this.Controls.Add(grid);//重要
grid.ForceInitialize();//重要
BestColumns(view);
view.OptionsPrint.AutoWidth = false;
return grid; }
然后数据分页创建
IPrintable[] arr(List<marketinformation> data)
{
List<IPrintable> Printable=new List<IPrintable>();
int PageIndex=;
int PageSize=;
int CurrentIndex=;
int TotalCount=data.Count;
for(PageIndex=;CurrentIndex<TotalCount;PageIndex++)
{
var PageData = data.Skip(PageIndex*PageSize).Take(PageSize).ToList();
Printable.Add(CreateGrid(PageData));
CurrentIndex=(PageIndex+)*PageSize;
}
return Printable.ToArray(); }

最后数据多的时候自动列宽或假死,可以循环固定列宽,也可以写字段名

void BestColumns(GridView view)
{
if (chkeds.Checked)
{
view.OptionsView.ColumnAutoWidth = false;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
switch (column.FieldName.ToString())
{
case "caccount":
view.Columns["caccount"].Width = ;
break;
case "cunitname":
view.Columns["cunitname"].Width = ;
break;
case "ddate":
view.Columns["ddate"].Width = ;
break;
case "cemskind":
view.Columns["cemskind"].Width = ;
break;
case "cnum":
view.Columns["cnum"].Width = ;
break;
case "dsysdate":
view.Columns["dsysdate"].Width = ;
break;
default:
view.Columns[column.FieldName].Width = ;
break;
}
}
}
}
else
{
view.OptionsView.ColumnAutoWidth = true;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
view.Columns[column.FieldName].Width = ;
}
}
} }

按钮上出现提示框

this.toolTipController1.AutoPopDelay = ;
ToolTipControllerShowEventArgs args = this.toolTipController1.CreateShowArgs();
this.toolTipController1.SetToolTip(this.button1, "请选择一条记录!");
this.toolTipController1.SetTitle(this.button1, "提示");
this.toolTipController1.SetToolTipIconType(this.button1,
DevExpress.Utils.ToolTipIconType.Exclamation);
this.toolTipController1.ShowBeak = true;
this.toolTipController1.ShowShadow = true;
this.toolTipController1.Rounded = true;
this.toolTipController1.ShowHint("请选择一条记录!", "提示");
args.ToolTip = "请选择一条记录!";
args.Title = "提示";
return;

用的控件是toolTipController

没数据控件显示文本

private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
{
if ((sender as GridView).RowCount == )
{
int width = ;
int height = ;
int font_size = ;
string str = "* 没有查询到数据!\r\n* no data found!";
Font f = new Font("微软雅黑", font_size, FontStyle.Bold);
Rectangle r = new Rectangle((e.Bounds.Width - width) / , (e.Bounds.Height - height) / , width, height);
e.Graphics.DrawString(str, f, Brushes.LightBlue, r);
e.Handled = true;
}
}

dev grid的一些使用的更多相关文章

  1. Dev Grid拖拽移动行

    效果图 源码下载 拖拽时带行截图效果实现代码 /// <summary> /// 拖拽帮助类 /// </summary> public static class DragHe ...

  2. dev grid 常用方法

    绑定数据源 public void Data(){DataTable td = new DataTable();DataRow row = td.NewRow();foreach (GridColum ...

  3. DevExpress Grid使用checkBox选中的方法

    到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...

  4. DEV控件Grid显示行号

    DEV控件Grid的显示行号需要通过一个事件来设置,具体设置代码为: private void gridView1_CustomDrawRowIndicator(object sender, DevE ...

  5. dev设置子窗体的初始位置,grid控件表头的属性设置

    当在父窗体上弹出子窗体时,一般设置子窗体的初始位置是居中, //在需要展示子窗体的父窗体上写这段,注意必须设置在show方法之前Form2 f2 = new Form2(); f2.MdiParent ...

  6. iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6

    In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...

  7. Dev GridView-Bind Detail Grid during runtime

    Here is a simple example. ASPX <%@ Page Language="C#" AutoEventWireup="true" ...

  8. dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项

    番外篇:. //该方法是将字符串转化为中文拼音的首写字母大写, public static string RemoveSpecialCharacters(string str){try{if (str ...

  9. dev中如何对combox下拉框设置可消除属性以及ASPxGridView中金额,数量的显示,以及总计、grid中某行值

    下拉框属性关键:IncrementalFilteringMode="StartsWith" DropDownStyle="DropDown" ASPxGridV ...

随机推荐

  1. TCP拥塞控制算法

    转自浅谈TCP拥塞控制算法 本篇文章介绍了几种经典的TCP拥塞控制算法,包括算法原理及各自适用场景. 回顾上篇文章:浅谈 redis 延迟 前言 TCP 通过维护一个拥塞窗口来进行拥塞控制,拥塞控制的 ...

  2. Ubuntu18.04 server安装步骤

    Ubuntu18.04 server安装步骤 1. select a language default 2.  select your location default 3. configure th ...

  3. Flume-Taildir Source 监控目录下多个文件的追加

    Exec source 适用于监控一个实时追加的文件,但不能保证数据不丢失:Spooldir Source 能够保证数据不丢失,且能够实现断点续传,但延迟较高,不能实时监控:而 Taildir Sou ...

  4. redis---set类型常用命令

    添加元素:sadd key value1 value2 查看指定key包含的元素:smembers key 判断指定元素是否存在于key的value中(0表示不存在,1表示存在):sismember ...

  5. 基于SAR对Linux资源的监控shell脚本

    #! /bin/bash ] # $# 传递给脚本或函数的参数个数 then 脚本名称 exit -; fi SLEEP_TIME=$ LOG=$ while true do #线程数 thread_ ...

  6. [Distributed ML] Yi WANG's talk

    王益,分布式机器学习的践行者,他的足迹值得后来者学习. 膜拜策略: LinkedIn高级分析师王益:大数据时代的理想主义和现实主义(图灵访谈)[心路历程] 分布式机器学习的故事-王益[历史由来] 分布 ...

  7. XLSX.js 导出Excel demo

    GitHub:https://github.com/SheetJS/js-xlsx 一个js操作Excel的工具,如下代码,很方便的就将json数据导出为Excel文件. 使用示例: //json 数 ...

  8. HTMLCollection对象和NodeList对象

    前言 首先我们先来看下面的demo,假如我们需要给所有的li字体变一个颜色. <!DOCTYPE html> <html lang="en"> <he ...

  9. loadrunner脚本因为没有token报错

    目录 场景 解决过程 解决方案 总结 场景 用loadrunner11录制脚本,处理后回放,加上检查点,报错找不到检查点对应的内容,去掉检查点,没有报错,但是打开页面没有该操作的痕迹.手动在页面上操作 ...

  10. MariaDB知识点总结02--日志+备份

    一.日志 1.查询日志 记录每一条sql语句,建议不开启,因为如果访问量较大,会占用相当大的资源,影响性能; vim /etc/my.cnf.d/server.cnf general_log = ON ...