dev grid的一些使用
保留选中数据,其他数据删除,不操作数据库
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的一些使用的更多相关文章
- Dev Grid拖拽移动行
效果图 源码下载 拖拽时带行截图效果实现代码 /// <summary> /// 拖拽帮助类 /// </summary> public static class DragHe ...
- dev grid 常用方法
绑定数据源 public void Data(){DataTable td = new DataTable();DataRow row = td.NewRow();foreach (GridColum ...
- DevExpress Grid使用checkBox选中的方法
到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...
- DEV控件Grid显示行号
DEV控件Grid的显示行号需要通过一个事件来设置,具体设置代码为: private void gridView1_CustomDrawRowIndicator(object sender, DevE ...
- dev设置子窗体的初始位置,grid控件表头的属性设置
当在父窗体上弹出子窗体时,一般设置子窗体的初始位置是居中, //在需要展示子窗体的父窗体上写这段,注意必须设置在show方法之前Form2 f2 = new Form2(); f2.MdiParent ...
- 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 ...
- Dev GridView-Bind Detail Grid during runtime
Here is a simple example. ASPX <%@ Page Language="C#" AutoEventWireup="true" ...
- dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项
番外篇:. //该方法是将字符串转化为中文拼音的首写字母大写, public static string RemoveSpecialCharacters(string str){try{if (str ...
- dev中如何对combox下拉框设置可消除属性以及ASPxGridView中金额,数量的显示,以及总计、grid中某行值
下拉框属性关键:IncrementalFilteringMode="StartsWith" DropDownStyle="DropDown" ASPxGridV ...
随机推荐
- Nginx之进程间的通信机制(共享内存、原子操作)
1. 概述 Linux 提供了多种进程间传递消息的方式,如共享内存.套接字.管道.消息队列.信号等,而 Nginx 框架使用了 3 种传递消息的传递方式:共享内存.套接字.信号. 在进程间访问共享资源 ...
- tp5 模型关联,多表联查实用方法
1.模型中建立关联关系 public function goods(){ return $this->belongsTo('app\common\model\goods\Goods', 'goo ...
- [Mybatis]执行一句Sql返回一个List<String>
在Mapper.xml如下书写SQL文,其中 resultType告知MyBatis返回的类型: <select id="selectExpiredDate" resultT ...
- 性能分析 | JVM发生内存溢出的8种原因及解决办法
推荐阅读:史上最详细JVM与性能优化知识点综合整理 1.Java 堆空间 2.GC 开销超过限制 3.请求的数组大小超过虚拟机限制 4.Perm gen 空间 5.Metaspace 6.无法新建本机 ...
- C realloc
https://baike.baidu.com/item/realloc/659993?fr=aladdin 也就是说:原地址后面有连续可以空间可以满足需要,则追加在后面,否则开辟新空间,并拷贝数据
- [面试] Java高级软件工程师面试考纲(转)
如果要应聘高级开发工程师职务,仅仅懂得Java的基础知识是远远不够的,还必须懂得常用数据结构.算法.网络.操作系统等知识.因此本文不会讲解具体的技术,笔者综合自己应聘各大公司的经历,整理了一份大公司对 ...
- LC 722. Remove Comments
Given a C++ program, remove comments from it. The program source is an array where source[i] is the ...
- python -v 和-V
python -v 小写v:这是版本信息,包括库版本 python -V 大写v:只看python的版本
- SMARTY核心
http://www.smarty.net/http://smarty.php.net/manual/en/ 1.配置 define("ROOTPATH",dirname(__FI ...
- IDEA结合GIT的使用
一.本地安装GIT 下载: https://git-scm.com/downloads 安装 略 配置环境变量 在 “我的电脑 --> 属性 --> 高级系统设置 -- > 环境变量 ...