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 ...
随机推荐
- php 中 使用foreach为数组增加键值对
php 中的 foreach 在php中,使用foreach来遍历数组的频率很高,并且其性能要高于 list() 和 each() 结合来遍历数组: 当遍历二位数组的第一层数组,并要给第二位数组增加一 ...
- Python 使用工具总结
1.比较两个list大小:operator模块 operator.lt(a, b) operator.le(a, b) operator.eq(a, b) operator.ne(a, b) oper ...
- Java-JVM OutOfMemory 情况(JDK8)
JVM 运行时内存结构(Run-Time Data Areas) 内存溢出分为两大类:OutOfMemoryError 和 StackOverflowError. 一.HeapOomError (JV ...
- JS初探
如何实现点击后,有下拉菜单的效果呢? 写一个JS效果的步骤: 一.先实现布局 二.实现原理 三.了解JS语法 1.JS获取效果元素 2.知道是什么事件(鼠标事件.键盘事件.表单事件.系统事件.自定义事 ...
- matlab gui界面设计记录
我们要进行的程序是彩色图像处理试验示例,用这个程序来练习我们的gui前台设计. 程序功能介绍:具有彩色图像处理及保存和音乐播放功能效果如下图 2 在MATLAB的命令窗口中输入guide命令,打开gu ...
- leetcode16 最接近的三数之和
做了几周的hard之后,这道题居然轻易就解出来了,稍微debug了一下就ac了,算是有了一丢丢提高把: 思路 这道题因为和三数之和很像,所以充分利用双指针的思想:先排序,然后再固定一个数i,i取值从[ ...
- application节点
<application>节点是AndroidManifest.xml文件中必须持有的一个节点,它包含在<manifest>节点下.通过<application>节 ...
- 深度学习之Faster-R-CNN
哎!还是看大神博客吧 https://blog.csdn.net/liuxiaoheng1992/article/details/81843363
- 在Android初次的前期学习中的二个小例子(2)
Hello13:SQLite数据库 一.简述SQLite的概念和主要特性 SQLite是一个轻量级的关系型数据库,运算速度快,占用资源少,使用非常方便,支持SQL语法标准和数据库事务原则. 相对于Sh ...
- 一百一十五:CMS系统之实现点击更换图形验证码功能
把验证码渲染到到页面上 访问,显然,是标签有个内边距 去掉内边距 加一个class 如果放大看的话,还有问题 用js实现点击更换图形验证码:生成查询字符串的形式访问图形验证码接口的url,放到img标 ...